Files
Project-M/Assets/_Project/Scripts/Simulation/Persistence/SaveApply.cs
T
kronic 73cfe2943d EB-1: machines can die - structures get HP, Husks raze them, wounded base persists
Structures (Turret/Wall/Pylon) reuse the combat spine: authoring bakes Health(GhostField)+DamageEvent buffer+a Destructible tag (no HitRadius -> no friendly projectile fire; no EffectiveCharacterStats -> clamp-to-0). HealthApplyDamageSystem destroys a Destructible at 0 (occupancy auto-frees). EnemyAISystem fortress-targets the weighted-nearest of players+structures via the shared EnemyAIMath.PickWeightedNearest (StructureAggroWeight TuningConfig knob, <1 prefers structures, squared factor; snapshot above the early-return so an undefended base is razed). Persistence v3: per-structure HP threaded through 5 sites (SaveData/PendingStructure/scan-guarded/BaseRestore same-ECB born-correct/WorldLauncher via SaveApply.ToPending); SaveService floor-gate [2,3] loads old saves. Loss feedback: proximity-gated StructureFeedbackSystem; CombatFeedbackSystem suppressed for structures. Pre-code review caught the DamageEvent-buffer crash blocker + 8 majors; post-code review clean. See DR-032.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-11 23:53:34 -07:00

35 lines
1.5 KiB
C#

using Unity.Entities;
namespace ProjectM.Simulation
{
/// <summary>
/// Pure save-apply helpers shared by the server spawn system (born-correct load) and EditMode tests.
/// Burst-safe: unmanaged, non-generic, no enums (avoids the cross-assembly-generic Burst ICE class).
/// </summary>
public static class SaveApply
{
/// <summary>Replace a StorageEntry ledger buffer's contents with a staged PendingSaveLedgerRow buffer.</summary>
public static void WriteLedger(DynamicBuffer<PendingSaveLedgerRow> src, DynamicBuffer<StorageEntry> dest)
{
dest.Clear();
for (int i = 0; i < src.Length; i++)
dest.Add(new StorageEntry { ItemId = src[i].ItemId, Count = src[i].Count });
}
/// <summary>EB-1: map a serialized <see cref="StructureSave"/> to the staged <see cref="PendingStructure"/>
/// (the menu->ServerWorld copy in WorldLauncher). Pure so the field-for-field copy — including the
/// easy-to-miss HP — is unit-tested; an omitted field here silently restores every structure at full HP.</summary>
public static PendingStructure ToPending(in StructureSave s) => new PendingStructure
{
Type = s.Type,
CellX = s.CellX,
CellZ = s.CellZ,
Direction = s.Direction,
RemainingTicks = s.RemainingTicks,
ConveyorResId = s.ConveyorResId,
ConveyorCount = s.ConveyorCount,
HP = s.HP,
};
}
}