Hazard: destructible cover — carve-able rocks that genuinely block until broken

Phase 1.5 long-term #8, the LAST 1.5 item (design review wf_e14dd739-069:
both HIGHs + the distinct MEDs verified before the session limit ate the
duplicate verifiers; unverified leftovers reasoned-closed in the spec).

Cover = a BlightClutter ghost (Variant 4) with a baked Environment-layer
BoxCollider: the runtime ghost's collider joins BuildPhysicsWorld ->
blocks the player CC and the enemy sweep while alive, and the gap opens
the instant the entity dies. Both hit paths already break it (the
clutter chassis); 8 hits to carve.

Review folds:
- HIGH: the 07-07 anti-stuck nudge would phase enemies THROUGH cover
  after ~1.5s (it exists to prevent room soft-locks). The nudge is now
  COVER-AWARE: a SphereCast identifies the blocker; a live BlightClutter
  ghost suppresses the phase (no soft-lock possible - the blocker is
  destructible); static-geometry wedges still nudge.
- HIGH: yield==durability made tanky cover an economy faucet. Deposit
  is DECOUPLED from the decrement at both hit sites: ScrapPerHit=0 =
  breaks in Remaining hits, yields NOTHING; fractional POSITIVE yields
  still credit >=1 (the B1 immortal-sink test pinned this - zero means
  zero, positive floors to 1).
- MEDs: HitRadius 1.2 (visual core, not a shot-eating disc), NO cover
  in Boss rooms (no boss depenetration backstop), scatter keep-out >=7u
  from the room origin (player landing + portal), Variant=4 explicit
  (the clutter block's explosive reroll cannot leak).
- Old static layer removed: 8 WorldColliders_RoomCover colliders
  (subscene) + the RoomCover_Visuals root (Game.unity).

Verified live: 3 cover ghosts spawned with SOLID baked colliders;
BLOCK - NudgeUntilTick stayed 0 across 3.5s of forced zero-progress
(old code arms at 1.5s); DEPENETRATE - an enemy shoved inside a live
rock exited to 1.7u (backstop holds against ghost colliders); CARVE -
the rock died to the real sweep and the spot probed OPEN. 470/470
EditMode; console clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 16:15:38 -07:00
parent d8e724e40a
commit bbf418e779
13 changed files with 386 additions and 1211 deletions
@@ -16,8 +16,8 @@ namespace ProjectM.Authoring
[Tooltip("Hit-points before the clutter shatters.")]
[Min(1)] public int Remaining = 2; // one-hit pop: both hit paths decrement by max(1,(int)ScrapPerHit)
[Tooltip("Scrap (Biomass) yielded per projectile hit — the 'minor scrap' trickle.")]
[Min(1f)] public float ScrapPerHit = 2f;
[Tooltip("Scrap (Biomass) yielded per hit. 0 = DESTRUCTIBLE COVER semantics: breaks in Remaining hits, yields nothing (deposit is decoupled from the decrement at both hit sites).")]
[Min(0f)] public float ScrapPerHit = 2f;
[Tooltip("Hit radius (world units) for the clear sweep.")]
[Min(0f)] public float HitRadius = 1.0f;
@@ -0,0 +1,35 @@
using ProjectM.Simulation;
using Unity.Entities;
using UnityEngine;
namespace ProjectM.Authoring
{
/// <summary>
/// Authoring for the baked <see cref="CoverFieldSpawner"/> singleton (mirrors ClutterFieldSpawnerAuthoring).
/// Place once in the gameplay subscene and assign the CoverRock ghost prefab; RoomFieldSystem scatters
/// destructible cover per room (never in Boss rooms) with an origin keep-out. Carries no transform.
/// </summary>
public class CoverFieldSpawnerAuthoring : MonoBehaviour
{
[Tooltip("CoverRock ghost prefab: BlightClutterAuthoring (ScrapPerHit=0, Variant=4) + an Environment-layer collider + a GhostAuthoringComponent (ownerless, interpolated).")]
public GameObject CoverPrefab;
[Tooltip("Cover rocks per room (Boss rooms get none).")]
[Min(0)] public int Count = 3;
private class CoverFieldSpawnerBaker : Baker<CoverFieldSpawnerAuthoring>
{
public override void Bake(CoverFieldSpawnerAuthoring authoring)
{
var entity = GetEntity(authoring, TransformUsageFlags.None);
AddComponent(entity, new CoverFieldSpawner
{
Prefab = authoring.CoverPrefab != null
? GetEntity(authoring.CoverPrefab, TransformUsageFlags.Dynamic)
: Entity.Null,
Count = authoring.Count,
});
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0a9b08ef91676fa4185406d9dec18c5e
@@ -630,8 +630,24 @@ namespace ProjectM.Server
nav.ValueRW.LastPos = npos;
if (st >= StuckUnstickTicks)
{
nav.ValueRW.NudgeUntilTick = TickUtil.NonZero(now + NudgeBurstTicks);
st = 0u;
// COVER-AWARE (destructible-cover review wf_e14dd739-069 HIGH): if what blocks this enemy
// is a LIVE cover GHOST (BlightClutter carrier), do NOT phase-nudge — cover must genuinely
// hold until the player breaks it. No soft-lock is possible: the blocker is destructible,
// and the counter stays primed so any OTHER wedge (static geometry) still nudges next check.
bool blockedByCover = false;
if (havePhysics)
{
float3 toTgt = nTarget - npos; toTgt.y = 0f;
float tl = math.length(toTgt);
if (tl > 1e-4f && physics.CollisionWorld.SphereCast(
npos, 0.35f, toTgt / tl, math.min(1.8f, tl), out var coverHit, envFilter))
blockedByCover = SystemAPI.HasComponent<BlightClutter>(coverHit.Entity);
}
if (!blockedByCover)
{
nav.ValueRW.NudgeUntilTick = TickUtil.NonZero(now + NudgeBurstTicks);
st = 0u;
}
}
nav.ValueRW.StuckTicks = st;
}
@@ -153,6 +153,11 @@ namespace ProjectM.Server
// A positive baked yield must always make progress: a raw (int) truncation of a sub-1.0 per-hit
// value would deposit 0 AND never decrement Remaining -> an immortal target that silently eats shots.
int amount = math.max(1, (int)tgtYieldPerHit[bestIdx]);
// DECOUPLED deposit (cover review wf_e14dd739-069): DESTRUCTIBLE COVER has ScrapPerHit=0 — it
// breaks in Remaining hits but yields NOTHING (durability must not be an economy faucet).
// Nodes/clutter (PerHit >= 1) keep deposit == decrement exactly as before.
// zero means ZERO (cover); any POSITIVE yield still credits >= 1 (the fractional-yield guard).
int deposit = tgtYieldPerHit[bestIdx] > 0f ? amount : 0;
byte yieldId = tgtYieldId[bestIdx];
// Route the yield into the HARVESTING player's PERSONAL inventory. The projectile carries the
@@ -162,8 +167,9 @@ namespace ProjectM.Server
if (m_GhostOwnerLookup.HasComponent(projEntity)
&& playerByConn.TryGetValue(m_GhostOwnerLookup[projEntity].NetworkId, out var ownedPlayer))
harvester = ownedPlayer;
HarvestMath.DepositYield(yieldId, amount, tgtToLedger[bestIdx], harvester,
m_InvLookup, ledger, true, haveDb, itemDb);
if (deposit > 0)
HarvestMath.DepositYield(yieldId, deposit, tgtToLedger[bestIdx], harvester,
m_InvLookup, ledger, true, haveDb, itemDb);
int rem = tgtRemaining[bestIdx] - amount;
tgtRemaining[bestIdx] = rem;
ecb.DestroyEntity(projEntity);
@@ -128,6 +128,33 @@ namespace ProjectM.Server
}
}
// DESTRUCTIBLE COVER (OPTIONAL singleton; review wf_e14dd739-069): never in Boss rooms (the boss
// has no depenetration backstop) and never inside the origin keep-out ring (player landing +
// portal). Variant stays the prefab's 4 — NEVER rerolled (the clutter block's explosive
// reroll must not leak into this copy).
if (plan.RoomType != RoomTypeId.Boss
&& SystemAPI.TryGetSingleton<CoverFieldSpawner>(out var cover)
&& cover.Prefab != Entity.Null)
{
var kBaked = SystemAPI.GetComponent<LocalTransform>(cover.Prefab);
var krng = new Random(RunMapMath.Hash(run.RunSeed, (uint)run.CurrentNodeId, 0xC0Eu) | 1u);
int kCount = math.clamp(cover.Count, 0, 6);
const float KeepOutFromOrigin = 7f;
for (int i = 0; i < kCount; i++)
{
float3 pos = origin;
for (int attempt = 0; attempt < 8; attempt++)
{
pos = RoomLayoutMath.ScatterInShape(plan.ShapeId, origin, i, kCount, ref krng);
if (math.distance(pos.xz, origin.xz) >= KeepOutFromOrigin) break;
}
if (math.distance(pos.xz, origin.xz) < KeepOutFromOrigin) continue; // unlucky draws: drop the piece
var e = ecb.Instantiate(cover.Prefab);
ecb.SetComponent(e, kBaked.WithPosition(pos));
ecb.AddComponent(e, new RoomTag { Room = room });
}
}
rf.LastSpawnedRoomEpoch = run.RoomEpoch;
SystemAPI.SetComponent(spawnerEntity, rf);
}
@@ -0,0 +1,22 @@
using Unity.Entities;
namespace ProjectM.Simulation
{
/// <summary>
/// Baked singleton holding the DESTRUCTIBLE COVER ghost prefab (Exploding_Barrels sibling —
/// Cover_Rock_Build: a BlightClutter carrier with ScrapPerHit=0, Variant=4, and a baked
/// Environment-layer collider that blocks the player CC and the enemy sweep while alive).
/// RoomFieldSystem scatters <see cref="Count"/> cover rocks per room epoch — EXCEPT Boss rooms
/// (the boss has no depenetration backstop; review wf_e14dd739-069) — with a keep-out ring
/// around the room origin (player landing + portal). OPTIONAL: absent singleton = no cover.
/// Mirrors <see cref="ClutterFieldSpawner"/>; carries no transform.
/// </summary>
public struct CoverFieldSpawner : IComponentData
{
/// <summary>Baked cover-rock ghost prefab to instantiate.</summary>
public Entity Prefab;
/// <summary>Cover rocks per room (Boss rooms get none).</summary>
public int Count;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0331196c0b301674189f1c1779f108da
@@ -270,6 +270,10 @@ namespace ProjectM.Simulation
continue;
int amount = math.max(1, (int)harvPerHit[i]);
// DECOUPLED deposit (cover review): cover has ScrapPerHit=0 — breaks in Remaining hits,
// yields nothing. Nodes/clutter (PerHit >= 1) keep deposit == decrement as before.
// zero means ZERO (cover); any POSITIVE yield still credits >= 1 (the fractional-yield guard).
int deposit = harvPerHit[i] > 0f ? amount : 0;
byte yieldId = harvYieldId[i];
// Route by region: Base nodes credit the shared ledger DIRECTLY (the build pool); an
// expedition / un-tagged target goes to the swinging player's PERSONAL inventory (spill to
@@ -278,10 +282,13 @@ namespace ProjectM.Simulation
Entity meleeHarvester = Entity.Null;
if (meleePlayerByConn.TryGetValue(hc.OwnerId, out var meleePlayer))
meleeHarvester = meleePlayer;
bool deposited = HarvestMath.DepositYield(yieldId, amount, harvToLedger[i], meleeHarvester,
m_InvLookup, ledger, haveLedger, haveDb, itemDb);
if (!deposited)
continue;
if (deposit > 0)
{
bool deposited = HarvestMath.DepositYield(yieldId, deposit, harvToLedger[i], meleeHarvester,
m_InvLookup, ledger, haveLedger, haveDb, itemDb);
if (!deposited)
continue; // never consume a YIELDING target for zero credit
}
int rem = harvRemaining[i] - amount;
harvRemaining[i] = rem;