Game.MapRequirementSystem
Assembly: Assembly-CSharp
Namespace: Game.UI.Editor
Type: class MapRequirementSystem
Base: GameSystemBase
Summary:
Manages detection and reporting of map resources and outside connections for the map editor / city start selection. The system:
- Collects available map features (area, buildable land, fertile land, forest, oil, ore, groundwater, fish, surface water) across the whole map and the configured starting tiles using Burst jobs and Unity's ECS job system.
- Queries water surface data to detect surface water inside starting tiles.
- Tracks presence of outside connections: roads, train, air, and electricity.
- Exposes synchronous query methods (StartingAreaHasResource and MapHasResource) and boolean properties indicating presence of starting area and outside connections.
Internally it uses MapTileSystem and WaterSystem, several EntityQueries to detect outside connection nodes, and holds persistent native arrays (9-element arrays for map/starting resources) and a NativeValue
All resource reads are protected by completing the internal JobHandle (m_ResultDependency) before returning results.
Fields
-
private MapTileSystem m_MapTileSystem
This cached reference provides starting tiles and tile-related data. -
private WaterSystem m_WaterSystem
Used to obtain WaterSurfaceData and register a surface reader for scheduled jobs. -
private EntityQuery m_TileQuery
Query matching MapTile + Geometry + MapFeatureElement (and excluding Temp/Deleted) used to build chunk arrays for the full-map resource collection job. -
private EntityQuery m_OutsideRoadNodeQuery
Query matching outside road nodes (Node + Road + OutsideConnection) used to set roadConnection. -
private EntityQuery m_OutsideTrainNodeQuery
Query matching outside train nodes (Node + TrainTrack + OutsideConnection) used to set trainConnection. -
private EntityQuery m_OutsideAirNodeQuery
Query matching outside airplane stops with outside connection used to set airConnection. -
private EntityQuery m_OutsideElectricityConnectionQuery
Query matching electricity outside connections used to set electricityConnection. -
private JobHandle m_ResultDependency
JobHandle referencing the scheduled collection jobs. The system calls Complete() on this handle before reading results in public query methods. -
private NativeValue<bool> m_WaterResult
Persistent container storing whether starting tiles contain surface water (written by CheckWaterJob). -
private NativeArray<bool> m_StartingAreaResources
Persistent 9-element array storing presence flags of each MapFeature type for the starting tiles (written by CollectStartingResourcesJob). -
private NativeArray<bool> m_MapResources
Persistent 9-element array storing presence flags of each MapFeature type across the full map (written by CollectResourcesJob). -
private TypeHandle __TypeHandle
Generated helper that caches component/buffer lookups and buffer type handles used by jobs. -
public struct CollectResourcesJob
(nested)
Burst-compiled IJob that iterates area archetype chunks and examines MapFeatureElement buffers to set flags in a provided NativeArrayrepresenting the map's available resources. -
public struct CollectStartingResourcesJob
(nested)
Burst-compiled IJob that iterates provided starting tile entities and reads their MapFeatureElement dynamic buffers (via BufferLookup) to set flags in a provided NativeArrayfor starting-area resources. -
public struct CheckWaterJob
(nested)
Burst-compiled IJob that inspects WaterSurfaceData depth values across the bounding area(s) of starting tiles (via Geometry component bounds) to determine if any surface water exists; writes result into a NativeValue. -
private struct TypeHandle
(nested)
Holds ComponentLookup, BufferLookup , and BufferTypeHandle for scheduler-safe access. Has an __AssignHandles method used during system setup.
Properties
-
public bool hasStartingArea { get; private set; }
True when MapTileSystem reports at least one starting tile. Updated each OnUpdate. -
public bool roadConnection { get; private set; }
True when any outside road connection nodes exist (set from m_OutsideRoadNodeQuery). -
public bool trainConnection { get; private set; }
True when any outside train connection nodes exist (set from m_OutsideTrainNodeQuery). -
public bool airConnection { get; private set; }
True when any outside airplane/air connections exist (set from m_OutsideAirNodeQuery). -
public bool electricityConnection { get; private set; }
True when any outside electricity connections exist (set from m_OutsideElectricityConnectionQuery).
Constructors
-
public MapRequirementSystem()
Default generated constructor. Initialization of persistent native containers is done in OnCreate. -
protected override void OnCreate()
Creates queries, obtains MapTileSystem and WaterSystem, allocates persistent NativeValueand NativeArray buffers (9 elements each) to store results. Also configures EntityQuery descriptors used later in OnUpdate.
Methods
-
protected override void OnUpdate()
Main scheduling method. Completes previous m_ResultDependency, fetches starting tiles, updates the public connection/starting-area booleans, schedules the CheckWaterJob (obtaining WaterSurfaceData from WaterSystem), schedules CollectStartingResourcesJob for starting tiles, schedules CollectResourcesJob for all map tiles (using m_TileQuery ToArchetypeChunkArray), and stores the resulting JobHandle in m_ResultDependency. Also registers the scheduled dependency with the WaterSystem as a reader. -
public bool StartingAreaHasResource(MapFeature feature)
Synchronous query to test whether a specified MapFeature exists in the configured starting area. Internally completes m_ResultDependency to ensure jobs are finished. For SurfaceWater, it returns true if either the starting-area MapFeature flags contain SurfaceWater or the water check (m_WaterResult) reported water. For the other MapFeature values it returns the value from m_StartingAreaResources. Returns false for invalid MapFeature values. -
public bool MapHasResource(MapFeature feature)
Synchronous query to test whether a specified MapFeature exists anywhere on the map. Completes m_ResultDependency and returns the flag from m_MapResources (if feature is in valid range). -
protected override void OnDestroy()
Disposes persistent NativeValue and NativeArray instances (m_WaterResult, m_StartingAreaResources, m_MapResources). -
private void __AssignQueries(ref SystemState state)
Compiler-generated helper (empty in this decompiled listing) used during OnCreateForCompiler to set up any dynamic EntityQueryBuilder usage. -
protected override void OnCreateForCompiler()
Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to prepare component lookups for job scheduling.
Usage Example
// Typical usage inside another system or UI code that can access MapRequirementSystem:
var mapReq = World.GetOrCreateSystemManaged<MapRequirementSystem>();
// After the MapRequirementSystem has run its update (it schedules jobs on its own),
// call these synchronous methods/properties to get final results:
bool hasStart = mapReq.hasStartingArea;
bool road = mapReq.roadConnection;
bool canStartWithWater = mapReq.StartingAreaHasResource(MapFeature.SurfaceWater);
bool mapHasOil = mapReq.MapHasResource(MapFeature.Oil);
// Note: StartingAreaHasResource and MapHasResource complete the internal job handle
// to ensure the data is up-to-date before returning.
Additional notes: - The system uses Burst-compiled jobs and Unity's ECS BufferLookup/BufferTypeHandle APIs — ensure you schedule/complete correctly when interacting with these methods. - The resource arrays are sized for nine MapFeature values; MapFeature enum ordering must match the indices used by this system.