Table of Contents

Struct UnitQueryBuilder

Namespace
Core.Queries
Assembly
Core.dll

Fluent query builder for unit filtering. Lazy evaluation - filters are applied when terminal operation is called.

Usage: using var results = new UnitQueryBuilder(unitSystem) .OwnedBy(countryId) .InProvince(provinceId) .Execute(Allocator.Temp);

Performance: O(U) where U = units, single pass with combined filters.

NOTE: This provides ENGINE-level queries (location, ownership, type ID). GAME layer should post-filter for game-specific concepts (unit class, combat role, etc.)

public struct UnitQueryBuilder

Constructors

UnitQueryBuilder(UnitSystem)

public UnitQueryBuilder(UnitSystem unitSystem)

Parameters

unitSystem UnitSystem

Methods

Any()

Check if any unit matches the filters.

public bool Any()

Returns

bool

Count()

Count matching units without allocating result list.

public int Count()

Returns

int

Dispose()

public void Dispose()

Execute(Allocator)

Execute query and return matching unit IDs. Caller must dispose the returned NativeList.

public NativeList<ushort> Execute(Allocator allocator)

Parameters

allocator Allocator

Returns

NativeList<ushort>

FirstOrDefault()

Get first matching unit, or 0 if none.

public ushort FirstOrDefault()

Returns

ushort

InProvince(ushort)

Filter to units in a specific province.

public UnitQueryBuilder InProvince(ushort provinceId)

Parameters

provinceId ushort

Returns

UnitQueryBuilder

NotOwnedBy(ushort)

Filter to units NOT owned by specific country (enemies).

public UnitQueryBuilder NotOwnedBy(ushort countryId)

Parameters

countryId ushort

Returns

UnitQueryBuilder

OfType(ushort)

Filter to units of a specific type ID.

public UnitQueryBuilder OfType(ushort unitTypeId)

Parameters

unitTypeId ushort

Returns

UnitQueryBuilder

OwnedBy(ushort)

Filter to units owned by specific country.

public UnitQueryBuilder OwnedBy(ushort countryId)

Parameters

countryId ushort

Returns

UnitQueryBuilder

TotalTroops()

Get total troop count of all matching units.

public int TotalTroops()

Returns

int

WithMaxTroops(ushort)

Filter to units with at most N troops.

public UnitQueryBuilder WithMaxTroops(ushort maxCount)

Parameters

maxCount ushort

Returns

UnitQueryBuilder

WithMinTroops(ushort)

Filter to units with at least N troops.

public UnitQueryBuilder WithMinTroops(ushort minCount)

Parameters

minCount ushort

Returns

UnitQueryBuilder

WithTroopCount(ushort, ushort)

Filter to units with troop count in range.

public UnitQueryBuilder WithTroopCount(ushort min, ushort max)

Parameters

min ushort
max ushort

Returns

UnitQueryBuilder