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>
This commit is contained in:
@@ -25,12 +25,14 @@ namespace ProjectM.Server
|
||||
{
|
||||
ComponentLookup<LocalTransform> m_TransformLookup;
|
||||
ComponentLookup<Conveyor> m_ConveyorLookup;
|
||||
ComponentLookup<Health> m_HealthLookup;
|
||||
|
||||
[BurstCompile]
|
||||
public void OnCreate(ref SystemState state)
|
||||
{
|
||||
m_TransformLookup = state.GetComponentLookup<LocalTransform>(isReadOnly: true);
|
||||
m_ConveyorLookup = state.GetComponentLookup<Conveyor>(isReadOnly: true);
|
||||
m_HealthLookup = state.GetComponentLookup<Health>(isReadOnly: true);
|
||||
state.RequireForUpdate<StructureCatalog>();
|
||||
state.RequireForUpdate<BaseAnchor>();
|
||||
state.RequireForUpdate<NetworkTime>();
|
||||
@@ -47,6 +49,7 @@ namespace ProjectM.Server
|
||||
|
||||
m_TransformLookup.Update(ref state);
|
||||
m_ConveyorLookup.Update(ref state);
|
||||
m_HealthLookup.Update(ref state);
|
||||
|
||||
var anchor = SystemAPI.GetSingleton<BaseAnchor>();
|
||||
var catalog = SystemAPI.GetBuffer<StructureCatalogEntry>(SystemAPI.GetSingletonEntity<StructureCatalog>());
|
||||
@@ -81,6 +84,14 @@ namespace ProjectM.Server
|
||||
NextTick = ProductionMath.RestoreNextTick(now, p.RemainingTicks),
|
||||
LastProcessedTick = TickUtil.NonZero(now),
|
||||
});
|
||||
// EB-1: restore the wounded HP born-correct in the SAME ecb as Instantiate (Health.Current is a
|
||||
// [GhostField]; a deferred set would leak baked Max to clients for one snapshot). Max + the
|
||||
// 0->full fallback come from the BAKED prefab, never the save. Automation machines lack Health.
|
||||
if (m_HealthLookup.HasComponent(prefab))
|
||||
{
|
||||
var hm = m_HealthLookup[prefab];
|
||||
ecb.SetComponent(structure, new Health { Current = p.HP > 0f ? p.HP : hm.Max, Max = hm.Max });
|
||||
}
|
||||
ecb.AddComponent(structure, new RegionTag { Region = RegionId.Base });
|
||||
ecb.AddComponent<RuntimePlacedTag>(structure);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user