Game.Areas.ValidationHelpers
Assembly: Assembly-CSharp
Namespace: Game.Areas
Type: static class
Base: System.Object
Summary:
{{ ValidationHelpers provides utility routines for validating area entities (polygons/brushes/triangles) in the game world. It checks area shapes for geometry errors (self-intersections, too-short edges, invalid shapes), validates triangles against existing objects, nets and other areas, enforces water / on-water / require-water rules, storage capacity checks and distance rules for lot owners. These helpers are used by the ValidationSystem to enqueue ErrorData describing problems detected when the player edits or places area-type prefabs (zones, lots, brushes, map tiles). }}
Fields
-
private struct OriginalAreaIterator
{{ Iterator used to query original/source areas when validating water/overlap checks — it inspects triangles of an existing area (the "original" area) to determine whether sample points lie inside that area (used to avoid false positives when an area is being replaced). }} -
private struct ObjectIterator
{{ Iterator run against the object quad-tree. For a target triangle it inspects nearby placed object entities and computes collision intersections (legs, circular bases, quads) to determine OverlapExisting, OnFire, Override/Warning severity and enqueues ErrorData. Handles owner chains, attached objects, prefab geometry flags and elevation. }} -
private struct NetIterator
{{ Iterator run against the net (roads) quad-tree. For a target triangle it inspects edges and nodes (and their geometry/composition) to detect overlaps between area triangles and net geometry. Computes intersection bounds and enqueues ErrorData for overlaps with roads, nodes or net pieces. }} -
private struct AreaIterator
{{ Iterator run against the area quad-tree. Detects overlaps between the validating area/triangle and other areas. Considers area flags (Slave, ProtectedArea, PhysicalGeometry), ownership chains, overriding semantics and sets appropriate error types and severities (OverlapExisting, ExceedsCityLimits, etc.). }} -
public struct BrushAreaIterator
{{ Public iterator used when a brush (map-editing brush) is being validated against existing protected map tiles. It checks protected areas (e.g. MapTile areas) and enqueues ExceedsCityLimits errors for brush samples that intersect map-tile-type protected geometry. }}
Properties
- (none)
{{ ValidationHelpers is a static utility class and does not expose properties. All functionality is provided via static methods and nested iterator types. }}
Constructors
- (none)
{{ Static class — no constructors. All methods are static and nested iterators are value types used by native quad-tree iteration. }}
Methods
-
public static void ValidateArea(bool editorMode, Entity entity, Temp temp, Owner owner, Area area, Geometry geometry, Storage storage, DynamicBuffer<Node> nodes, PrefabRef prefabRef, ValidationSystem.EntityData data, NativeQuadTree<Entity, QuadTreeBoundsXZ> objectSearchTree, NativeQuadTree<Entity, QuadTreeBoundsXZ> netSearchTree, NativeQuadTree<AreaSearchItem, QuadTreeBoundsXZ> areaSearchTree, WaterSurfaceData waterSurfaceData, TerrainHeightData terrainHeightData, NativeQueue<ErrorData>.ParallelWriter errorQueue)
{{ Full-area validation entry point. Validates the entire area (all nodes/triangles) for geometry problems, shape validity, triangle validation, owner/lot distance checks, storage capacity, and water-related rules. It builds and uses iterators to query object/net/area quad-trees and enqueues ErrorData describing problems. Parameters include editing mode, temporary flags, owner relationship, area geometry buffers, environment data (water/terrain), and native quad-tree references. }} -
private static bool CheckShape(Line3.Segment line1, float3 node2, Entity entity, float minNodeDistance, NativeQueue<ErrorData>.ParallelWriter errorQueue)
{{ Basic edge-to-node proximity check: ensures a node is not too close to an edge. If distance < minNodeDistance, enqueues InvalidShape error with a position halfway between the node and the closest point on the segment. Returns false when invalid. Used for simple quick validation checks. }} -
private static bool CheckShape(Line3.Segment line1, float3 node2, Entity entity, float minNodeDistance, NativeQueue<ErrorData>.ParallelWriter errorQueue, DynamicBuffer<Node> nodes, int index1, int index2, bool isComplete, bool isCounterClockwise)
{{ Extended node/edge check that also considers adjacent edge quads and lines (using GetEdgeQuad/GetEdgeLine) to avoid false positives for adjacent edges. Enqueues InvalidShape when a problematic proximity is found and the geometry truly intersects those expanded edge regions. }} -
private static bool CheckShape(Line3.Segment line1, Line3.Segment line2, Entity entity, float minNodeDistance, NativeQueue<ErrorData>.ParallelWriter errorQueue, DynamicBuffer<Node> nodes, int index1, int index2, bool isComplete, bool isCounterClockwise)
{{ Edge-to-edge proximity check. If two segments are closer than minNodeDistance, it checks expanded quads for those edges to determine whether the shape is truly invalid; enqueues InvalidShape when appropriate. }} -
private static Line2.Segment GetEdgeLine(float minNodeDistance, DynamicBuffer<Node> nodes, int index, bool isComplete, bool isCounterClockwise)
{{ Helper: computes a 2D edge segment expanded/offset from the stored node at index, used by shape checks to build test segments accounting for node expansion (min distance). }} -
private static Quad2 GetEdgeQuad(float minNodeDistance, DynamicBuffer<Node> nodes, int index, bool isComplete, bool isCounterClockwise)
{{ Helper: computes a 2D quad representing a region around an area edge (two expanded nodes), used to test whether a point or segment falls into the expanded edge area (used to suppress false positives). }} -
public static void ValidateTriangle(bool editorMode, bool noErrors, bool isCounterClockwise, Entity entity, Temp temp, Owner owner, Triangle triangle, ValidationSystem.EntityData data, NativeQuadTree<Entity, QuadTreeBoundsXZ> objectSearchTree, NativeQuadTree<Entity, QuadTreeBoundsXZ> netSearchTree, NativeQuadTree<AreaSearchItem, QuadTreeBoundsXZ> areaSearchTree, WaterSurfaceData waterSurfaceData, TerrainHeightData terrainHeightData, NativeQueue<ErrorData>.ParallelWriter errorQueue)
{{ Validates a single triangle of an area. It computes triangle bounds and height ranges, obtains area geometry, sets collision flags, then runs iterators (ObjectIterator, NetIterator, AreaIterator) to detect collisions and overlaps with placed objects, nets and other areas. Also performs water checks (InWater / NoWater) by sampling the water surface and compares to requirements. Enqueues ErrorData for any violations. The noErrors flag and owner/asset logic influence ignored entities and severity (e.g. warnings for temporary/attached objects). }}
Usage Example
// Example: validate an Area entity from within ValidationSystem-like context.
// (This is illustrative; in-game you call this with real NativeQuadTree and data.)
ValidationHelpers.ValidateArea(
editorMode: false,
entity: areaEntity,
temp: tempComponent,
owner: ownerComponent,
area: areaComponent,
geometry: geometryComponent,
storage: storageComponent,
nodes: areaNodesBuffer,
prefabRef: prefabRef,
data: validationEntityData,
objectSearchTree: objectQuadTree,
netSearchTree: netQuadTree,
areaSearchTree: areaQuadTree,
waterSurfaceData: waterSurface,
terrainHeightData: terrainHeights,
errorQueue: errorQueueParallelWriter
);
{{ Notes: - This class is tightly integrated with the game's ECS (Unity.Entities) and uses NativeQuadTree iterators; callers must supply valid NativeQuadTree instances and ValidationSystem.EntityData (buffers and component lookups). - Errors are reported by enqueuing ErrorData into the provided NativeQueue