Game.Simulation.FirewatchTowerAISystem
Assembly: Assembly-CSharp (inferred)
Namespace: Game.Simulation
Type: public class FirewatchTowerAISystem
Base: GameSystemBase
Summary:
System that ensures Firewatch Tower buildings are marked as having coverage each simulation update. It schedules a Burst-compiled IJobChunk (FirewatchTowerTickJob) that iterates FirewatchTower components and sets the HasCoverage flag on their m_Flags field. The system updates on a coarse interval (GetUpdateInterval returns 256) with an offset of 16 and only runs when there are matching entities (FirewatchTower + PrefabRef, excluding Temp/Destroyed/Deleted). The implementation includes compiler helper methods and a TypeHandle to obtain a ComponentTypeHandle for FirewatchTower components.
Fields
-
private EntityQuery m_BuildingQuery
Stores the query used to select the Firewatch Tower entities the system processes. The query requires a FirewatchTower component and a PrefabRef, and excludes Temp, Destroyed and Deleted. -
private TypeHandle __TypeHandle
Container for component type handles used by the system. Populated via __AssignHandles and used when scheduling jobs. -
private struct TypeHandle.__Game_Buildings_FirewatchTower_RW_ComponentTypeHandle
(ComponentTypeHandle)
A ComponentTypeHandle for read/write access to Game.Buildings.FirewatchTower components. Assigned from the SystemState in OnCreateForCompiler / before scheduling the job. -
private struct FirewatchTowerTickJob
(nested, Burst compiled)
Job struct that implements IJobChunk. It contains: public ComponentTypeHandle<Game.Buildings.FirewatchTower> m_FirewatchTowerType
— the handle used to get the FirewatchTower native array from a chunk. The job iterates each FirewatchTower in the chunk and sets the HasCoverage flag on the component's m_Flags.
Properties
- None (no public properties exposed by this system)
Constructors
public FirewatchTowerAISystem()
Default constructor; marked with [Preserve] attribute in the source. No custom initialization beyond base construction.
Methods
-
public override int GetUpdateInterval(SystemUpdatePhase phase)
Returns 256. Indicates the system is intended to run once every 256 frames (coarse periodic update). -
public override int GetUpdateOffset(SystemUpdatePhase phase)
Returns 16. Provides an offset into the update interval to stagger work across systems/frames. -
[Preserve] protected override void OnCreate()
Creates and configures the EntityQuery (m_BuildingQuery) to select entities that: - Have FirewatchTower (read-only in the query signature),
- Have PrefabRef (read-only),
-
Do not have Temp, Destroyed or Deleted. Also calls RequireForUpdate(m_BuildingQuery) so the system only updates when matching entities exist.
-
[Preserve] protected override void OnUpdate()
Builds and schedules the FirewatchTowerTickJob in parallel. It populates the job's m_FirewatchTowerType using InternalCompilerInterface.GetComponentTypeHandle and the system's type handle state, schedules the job with JobChunkExtensions.ScheduleParallel against m_BuildingQuery, and assigns the JobHandle to base.Dependency. -
protected override void OnCreateForCompiler()
Called to wire up compiler-time helper data: calls __AssignQueries and assigns component handles via __TypeHandle.__AssignHandles. This method supports generated/compiled pipeline expectations. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Compiler helper that currently constructs (and disposes) a temporary EntityQueryBuilder. Present for generated boilerplate integration; no runtime query assignment beyond what OnCreate does. -
private struct FirewatchTowerTickJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Job chunk execution method obtains a NativeArrayfrom the chunk via m_FirewatchTowerType and for each element sets: value.m_Flags |= FirewatchTowerFlags.HasCoverage; then writes the element back to the array. The struct is Burst-compiled and implements IJobChunk.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Query that selects Firewatch Tower building instances (non-temp, not destroyed/deleted)
m_BuildingQuery = GetEntityQuery(
ComponentType.ReadOnly<Game.Buildings.FirewatchTower>(),
ComponentType.ReadOnly<PrefabRef>(),
ComponentType.Exclude<Temp>(),
ComponentType.Exclude<Destroyed>(),
ComponentType.Exclude<Deleted>());
RequireForUpdate(m_BuildingQuery);
}
[Preserve]
protected override void OnUpdate()
{
var job = new FirewatchTowerTickJob
{
m_FirewatchTowerType = InternalCompilerInterface.GetComponentTypeHandle(
ref __TypeHandle.__Game_Buildings_FirewatchTower_RW_ComponentTypeHandle,
ref base.CheckedStateRef)
};
base.Dependency = JobChunkExtensions.ScheduleParallel(job, m_BuildingQuery, base.Dependency);
}
Notes and implementation caveats: - The job uses write access to the FirewatchTower component type and modifies the m_Flags field in-place. Ensure the component layout and flags enum (FirewatchTowerFlags.HasCoverage) match expectations in the game's component definition. - The system relies on generated/compiled helpers (InternalCompilerInterface, CheckedStateRef, OnCreateForCompiler) — this pattern is typical for code produced/consumed by Unity's DOTS/ECS tooling and may require the surrounding runtime scaffolding to work correctly in a modding context.