73cfe2943d
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>
44 lines
2.0 KiB
C#
44 lines
2.0 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace ProjectM.Authoring
|
|
{
|
|
/// <summary>
|
|
/// Generic authoring for a non-functional build-structure ghost prefab (Wall / Pylon) — duplicate
|
|
/// Turret.prefab so the ownerless interpolated GhostAuthoringComponent on PlacedStructure.Type comes free,
|
|
/// then swap TurretAuthoring for this. Bakes ONLY <see cref="PlacedStructure"/>{Type=<see cref="Kind"/>}
|
|
/// (no <see cref="Turret"/> stats, so TurretFireSystem ignores it). BuildPlaceSystem overrides Cell +
|
|
/// LastProcessedTick and adds RegionTag{Base} at placement. <see cref="Kind"/> is a byte (StructureType.*) to
|
|
/// dodge the cross-assembly enum-in-Burst hazard and the MCP enum-drop gotcha.
|
|
/// </summary>
|
|
public class StructureAuthoring : MonoBehaviour
|
|
{
|
|
[Tooltip("StructureType byte: 5 = Wall, 6 = Pylon (do NOT use 1-4: Turret + reserved M7 automation).")]
|
|
public byte Kind = StructureType.Wall;
|
|
|
|
[Min(1f)] public float MaxHp = 150f;
|
|
|
|
private class StructureBaker : Baker<StructureAuthoring>
|
|
{
|
|
public override void Bake(StructureAuthoring authoring)
|
|
{
|
|
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
|
|
AddComponent(entity, new PlacedStructure
|
|
{
|
|
Type = authoring.Kind,
|
|
Cell = default,
|
|
NextTick = 0u,
|
|
LastProcessedTick = 0u,
|
|
});
|
|
// EB-1: Wall/Pylon are damageable + destructible AI targets (a wall soaks Husk strikes that would
|
|
// otherwise hit a turret). DamageEvent buffer MUST exist or an AI strike crashes at ECB playback.
|
|
// No HitRadius -> ProjectileDamageSystem ignores them (no friendly projectile fire).
|
|
AddComponent(entity, new Health { Current = authoring.MaxHp, Max = authoring.MaxHp });
|
|
AddBuffer<DamageEvent>(entity);
|
|
AddComponent<Destructible>(entity);
|
|
}
|
|
}
|
|
}
|
|
}
|