Struct UnitQueryBuilder
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
unitSystemUnitSystem
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
allocatorAllocator
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
provinceIdushort
Returns
NotOwnedBy(ushort)
Filter to units NOT owned by specific country (enemies).
public UnitQueryBuilder NotOwnedBy(ushort countryId)
Parameters
countryIdushort
Returns
OfType(ushort)
Filter to units of a specific type ID.
public UnitQueryBuilder OfType(ushort unitTypeId)
Parameters
unitTypeIdushort
Returns
OwnedBy(ushort)
Filter to units owned by specific country.
public UnitQueryBuilder OwnedBy(ushort countryId)
Parameters
countryIdushort
Returns
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
maxCountushort
Returns
WithMinTroops(ushort)
Filter to units with at least N troops.
public UnitQueryBuilder WithMinTroops(ushort minCount)
Parameters
minCountushort
Returns
WithTroopCount(ushort, ushort)
Filter to units with troop count in range.
public UnitQueryBuilder WithTroopCount(ushort min, ushort max)
Parameters
minushortmaxushort