Files
kronic 2da29783fd EB-2: felt spend - turrets burn a shared Charge pool, ledger-fed Fabricator mints it from Ore
Mined Ore now has an ongoing sink: a ledger-fed Fabricator converts Ore->Charge
(1 Ore -> 3 Charge / 30t) and turrets spend Charge per shot, soft-failing (no
shot, no cooldown burn) when the shared pool runs dry.

- ResourceId.Charge=4 rides the existing [GhostField] StorageEntry ledger (no new wire).
- TurretFireSystem: single ledger resolve + atomic spend / soft-fail / partial-refund.
- Fabricator.InputFromLedger (byte, server-only) feeds input from the shared ledger,
  read live in-loop so two machines split a finite pool; both modes deposit to ledger.
- HudSystem: violet Charge chip + global quiet-turret cue when siege && Charge==0.
- StorageMath.TotalOf backs the affordability read; catalog re-enables the Fabricator (4 entries).

See DR-033.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-12 19:14:52 -07:00

92 lines
4.2 KiB
C#

using Unity.Entities;
namespace ProjectM.Simulation
{
/// <summary>
/// A fixed-yield resource generator — the FRONT of the M7 auto-gather chain (Harvester -> Conveyor ->
/// Fabricator). Each period it deposits <see cref="Yield"/> of <see cref="ResourceId"/> into its OWN
/// server-only <see cref="MachineOutput"/> buffer (a conveyor pulls it onward). Server-only data (NO
/// [GhostField]); the client only ever sees <c>PlacedStructure.Type</c>. Reuses
/// <c>PlacedStructure.NextTick</c>/<c>LastProcessedTick</c> for the deterministic, within-session catch-up
/// cadence (see <c>HarvesterProductionSystem</c>).
/// </summary>
public struct Harvester : IComponentData
{
/// <summary>Resource id produced (a byte; see <see cref="ResourceId"/>).</summary>
public byte ResourceId;
/// <summary>Units produced per elapsed period.</summary>
public int Yield;
/// <summary>Server ticks between productions.</summary>
public int PeriodTicks;
}
/// <summary>
/// A recipe machine — the BACK of the M7 chain. Consumes <see cref="InAmount"/> of <see cref="InResourceId"/>
/// per run from its own <see cref="MachineInput"/> buffer (fed by a conveyor) and deposits <see cref="OutAmount"/>
/// of <see cref="OutResourceId"/> into the GLOBAL ledger. Strictly input-limited (never mints from an empty
/// slot). Server-only data.
/// </summary>
public struct Fabricator : IComponentData
{
public byte InResourceId;
public int InAmount;
public byte OutResourceId;
public int OutAmount;
public int PeriodTicks;
/// <summary>EB-2: 0 = consume the input from the MachineInput buffer (the M7 conveyor chain); !=0 = consume
/// the input from the SHARED ledger (a base-loop ledger-fed Fabricator, e.g. Ore -> Charge). Server-only, NO [GhostField].</summary>
public byte InputFromLedger;
}
/// <summary>
/// A directional transport belt — the MIDDLE of the M7 chain. Each period it pulls one item off an adjacent
/// upstream <see cref="MachineOutput"/> (when empty) and advances a held <see cref="ConveyorItem"/> exactly one
/// cell toward <see cref="Direction"/>. <see cref="Direction"/> is a byte (0=+X,1=-X,2=+Z,3=-Z) — never an enum
/// (the cross-assembly enum-in-Burst hazard). Server-only data.
/// </summary>
public struct Conveyor : IComponentData
{
/// <summary>Belt facing: 0=+X, 1=-X, 2=+Z, 3=-Z (see <c>ConveyorMath.DirOffset</c>).</summary>
public byte Direction;
public int PeriodTicks;
}
/// <summary>
/// A machine's INPUT staging buffer (server-only, NO [GhostField] -> never replicated). A DISTINCT element type
/// from the global ledger's <see cref="StorageEntry"/> (so <c>GetSingleton&lt;StorageEntry&gt;</c> stays
/// unambiguous) and from <see cref="MachineOutput"/> (so a machine can carry both without a buffer-type clash).
/// </summary>
public struct MachineInput : IBufferElementData
{
public byte ResourceId;
public int Count;
}
/// <summary>A machine's OUTPUT staging buffer (server-only, NO [GhostField]). See <see cref="MachineInput"/>.</summary>
public struct MachineOutput : IBufferElementData
{
public byte ResourceId;
public int Count;
}
/// <summary>
/// The single in-flight item a conveyor carries. An ENABLEABLE component (enabled = the belt is occupied) so a
/// transport step is a bit-flip + field copy, never a structural change. Baked DISABLED (an empty belt).
/// Server-only.
/// </summary>
public struct ConveyorItem : IComponentData, IEnableableComponent
{
public byte ResourceId;
public int Count;
}
/// <summary>
/// Marks a structure PLACED by a player at runtime (BuildPlaceSystem) or restored from a save — i.e. the
/// persistable set, as opposed to anything baked into the subscene. SaveWriteSystem scans only these and
/// BaseRestoreSystem re-adds the tag, so save/restore is the single source of truth for player builds.
/// Server-only (not replicated).
/// </summary>
public struct RuntimePlacedTag : IComponentData { }
}