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>
48 lines
2.1 KiB
C#
48 lines
2.1 KiB
C#
using ProjectM.Simulation;
|
|
using Unity.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace ProjectM.Authoring
|
|
{
|
|
/// <summary>
|
|
/// Authoring for the turret structure ghost prefab (duplicate UpgradePickup.prefab so the ownerless
|
|
/// interpolated GhostAuthoringComponent comes free). Bakes <see cref="PlacedStructure"/>{Type=Turret} +
|
|
/// <see cref="Turret"/> stats. BuildPlaceSystem stamps Cell + LastProcessedTick at placement.
|
|
/// </summary>
|
|
public class TurretAuthoring : MonoBehaviour
|
|
{
|
|
[Min(1f)] public float Range = 10f;
|
|
[Min(1)] public int CooldownTicks = 30;
|
|
[Min(1f)] public float Damage = 12f;
|
|
[Min(1f)] public float MaxHp = 120f;
|
|
|
|
private class TurretBaker : Baker<TurretAuthoring>
|
|
{
|
|
public override void Bake(TurretAuthoring authoring)
|
|
{
|
|
var entity = GetEntity(authoring, TransformUsageFlags.Dynamic);
|
|
AddComponent(entity, new PlacedStructure
|
|
{
|
|
Type = StructureType.Turret,
|
|
Cell = default,
|
|
NextTick = 0u,
|
|
LastProcessedTick = 0u,
|
|
});
|
|
AddComponent(entity, new Turret
|
|
{
|
|
Range = authoring.Range,
|
|
CooldownTicks = authoring.CooldownTicks,
|
|
Damage = authoring.Damage,
|
|
});
|
|
// EB-1: structures are damageable + destructible (Husks push for them; HealthApplyDamageSystem
|
|
// destroys a Destructible at Health<=0). The DamageEvent buffer MUST exist on the archetype or an
|
|
// AI/turret strike crashes at ECB playback. NO HitRadius on purpose -> ProjectileDamageSystem (needs
|
|
// Health+HitRadius) ignores structures, so player shots never friendly-fire your own turret.
|
|
AddComponent(entity, new Health { Current = authoring.MaxHp, Max = authoring.MaxHp });
|
|
AddBuffer<DamageEvent>(entity);
|
|
AddComponent<Destructible>(entity);
|
|
}
|
|
}
|
|
}
|
|
}
|