Class ProvinceQueries
High-performance province data access layer Provides optimized queries for province information Performance: All basic queries <0.01ms, cached complex queries
public class ProvinceQueries
- Inheritance
-
objectProvinceQueries
Constructors
ProvinceQueries(ProvinceSystem, CountrySystem, AdjacencySystem)
public ProvinceQueries(ProvinceSystem provinceSystem, CountrySystem countrySystem, AdjacencySystem adjacencySystem = null)
Parameters
provinceSystemProvinceSystemcountrySystemCountrySystemadjacencySystemAdjacencySystem
Methods
CalculateDistancesFromCountry(ushort)
Get distances from all provinces of a country. Useful for influence calculations. Returns byte.MaxValue for provinces that are unreachable. Performance target: less than 30ms
public void CalculateDistancesFromCountry(ushort countryId)
Parameters
countryIdushort
Dispose()
public void Dispose()
Exists(ushort)
Check if province exists Performance target: <0.001ms
public bool Exists(ushort provinceId)
Parameters
provinceIdushort
Returns
- bool
GetAllProvinceIds(Allocator)
Get all active province IDs Returns native array that must be disposed by caller Performance target: <1ms for 10k provinces
public NativeArray<ushort> GetAllProvinceIds(Allocator allocator = Allocator.TempJob)
Parameters
allocatorAllocator
Returns
- NativeArray<ushort>
GetCachedProvinceDistance(ushort)
Get province distance from the last CalculateDistancesFromCountry call. Must call CalculateDistancesFromCountry first.
public byte GetCachedProvinceDistance(ushort provinceId)
Parameters
provinceIdushort
Returns
- byte
GetConnectedLandmasses(ushort, Allocator)
Find all connected landmasses owned by a country. Returns a list of province groups (each group is a connected landmass). Each inner list must be disposed by caller. Performance target: less than 30ms
public NativeList<NativeList<ushort>> GetConnectedLandmasses(ushort countryId, Allocator allocator = Allocator.TempJob)
Parameters
countryIdushortallocatorAllocator
Returns
- NativeList<NativeList<ushort>>
GetConnectedProvincesOfSameOwner(ushort, Allocator)
Find all provinces connected to source that belong to the same country. Uses flood-fill through adjacency graph. Returns native list that must be disposed by caller. Performance target: less than 20ms
public NativeList<ushort> GetConnectedProvincesOfSameOwner(ushort sourceProvinceId, Allocator allocator = Allocator.TempJob)
Parameters
sourceProvinceIdushortallocatorAllocator
Returns
- NativeList<ushort>
GetConnectedProvincesWithOwner(ushort, ushort, Allocator)
Find all provinces connected to source that have a specific owner. Uses flood-fill through adjacency graph. Returns native list that must be disposed by caller. Performance target: less than 20ms
public NativeList<ushort> GetConnectedProvincesWithOwner(ushort sourceProvinceId, ushort targetOwnerId, Allocator allocator = Allocator.TempJob)
Parameters
sourceProvinceIdushorttargetOwnerIdushortallocatorAllocator
Returns
- NativeList<ushort>
GetCountryProvinceCount(ushort)
Get number of provinces owned by a country Performance target: <2ms for 10k provinces
public int GetCountryProvinceCount(ushort countryId)
Parameters
countryIdushort
Returns
- int
GetCountryProvinces(ushort, Allocator)
Get all provinces owned by a specific country Returns native array that must be disposed by caller Performance target: <5ms for 10k provinces
public NativeArray<ushort> GetCountryProvinces(ushort countryId, Allocator allocator = Allocator.TempJob)
Parameters
countryIdushortallocatorAllocator
Returns
- NativeArray<ushort>
GetCountryProvinces(ushort, NativeList<ushort>)
Get all provinces owned by a specific country (fills existing NativeList) Zero-allocation overload for hot paths (monthly tick, etc.) Performance target: <5ms for 10k provinces
public void GetCountryProvinces(ushort countryId, NativeList<ushort> resultBuffer)
Parameters
countryIdushortresultBufferNativeList<ushort>
GetDistanceBetween(ushort, ushort)
Get distance between two provinces (BFS hops). Returns byte.MaxValue if unreachable or AdjacencySystem not available. Performance target: less than 5ms
public byte GetDistanceBetween(ushort province1, ushort province2)
Parameters
province1ushortprovince2ushort
Returns
- byte
GetLandProvinces(Allocator)
Get land provinces (non-ocean) Returns native array that must be disposed by caller Performance target: <5ms for 10k provinces
public NativeArray<ushort> GetLandProvinces(Allocator allocator = Allocator.TempJob)
Parameters
allocatorAllocator
Returns
- NativeArray<ushort>
GetLandmassCount(ushort)
Get number of separate landmasses owned by a country. Useful for detecting if a country has disconnected territories. Performance target: less than 30ms
public int GetLandmassCount(ushort countryId)
Parameters
countryIdushort
Returns
- int
GetOceanProvinces(Allocator)
Get ocean provinces Returns native array that must be disposed by caller Performance target: <5ms for 10k provinces
public NativeArray<ushort> GetOceanProvinces(Allocator allocator = Allocator.TempJob)
Parameters
allocatorAllocator
Returns
- NativeArray<ushort>
GetOwner(ushort)
Get province owner - most common query (must be ultra-fast) Performance target: <0.001ms
public ushort GetOwner(ushort provinceId)
Parameters
provinceIdushort
Returns
- ushort
GetPerformanceStats()
Get query performance statistics
public static QueryPerformanceStats GetPerformanceStats()
Returns
GetProvinceOwnerColor(ushort)
Get the color of the country that owns this province Performance target: <0.01ms
public Color32 GetProvinceOwnerColor(ushort provinceId)
Parameters
provinceIdushort
Returns
GetProvinceOwnerTag(ushort)
Get the tag of the country that owns this province Performance target: <0.01ms
public string GetProvinceOwnerTag(ushort provinceId)
Parameters
provinceIdushort
Returns
- string
GetProvinceState(ushort)
Get complete province state (8-byte struct) Performance target: <0.001ms
public ProvinceState GetProvinceState(ushort provinceId)
Parameters
provinceIdushort
Returns
GetProvinceStatistics()
Get province statistics for debugging/UI (engine-only data) Performance target: <10ms for 10k provinces Note: Development stats removed (game-specific)
public ProvinceStatistics GetProvinceStatistics()
Returns
GetProvincesBorderingCountry(ushort, ushort, Allocator)
Get all provinces that border a specific country, filtered by owner. Example: Get all YOUR provinces that border enemy country X. Returns native list that must be disposed by caller. Performance target: less than 15ms
public NativeList<ushort> GetProvincesBorderingCountry(ushort countryId, ushort filterOwnerId, Allocator allocator = Allocator.TempJob)
Parameters
countryIdushortfilterOwnerIdushortallocatorAllocator
Returns
- NativeList<ushort>
GetProvincesBorderingCountry(ushort, Allocator)
Get all provinces that border a specific country (adjacent to but not owned by). Useful for finding invasion targets, border fortification candidates, etc. Returns native list that must be disposed by caller. Performance target: less than 15ms
public NativeList<ushort> GetProvincesBorderingCountry(ushort countryId, Allocator allocator = Allocator.TempJob)
Parameters
countryIdushortallocatorAllocator
Returns
- NativeList<ushort>
GetProvincesByOwnerTag(string, Allocator)
Get provinces owned by countries with a specific tag pattern Example: Get all provinces owned by countries with tags starting with "GER" Returns native array that must be disposed by caller Performance target: <10ms for 10k provinces
public NativeArray<ushort> GetProvincesByOwnerTag(string tagPattern, Allocator allocator = Allocator.TempJob)
Parameters
tagPatternstringallocatorAllocator
Returns
- NativeArray<ushort>
GetProvincesByTerrain(ushort, Allocator)
Get provinces by terrain type Returns native array that must be disposed by caller Performance target: <5ms for 10k provinces
public NativeArray<ushort> GetProvincesByTerrain(ushort terrainType, Allocator allocator = Allocator.TempJob)
Parameters
terrainTypeushortallocatorAllocator
Returns
- NativeArray<ushort>
GetProvincesWithinDistance(ushort, byte, Allocator)
Get all provinces within N hops of a source province. Requires AdjacencySystem to be available. Returns native list that must be disposed by caller. Performance target: less than 20ms for distance=10
public NativeList<ushort> GetProvincesWithinDistance(ushort sourceProvinceId, byte maxDistance, Allocator allocator = Allocator.TempJob)
Parameters
sourceProvinceIdushortmaxDistancebyteallocatorAllocator
Returns
- NativeList<ushort>
GetTerrain(ushort)
Get province terrain type (now ushort) Performance target: <0.001ms
public ushort GetTerrain(ushort provinceId)
Parameters
provinceIdushort
Returns
- ushort
GetTotalProvinceCount()
Get total number of provinces in the system Performance target: <0.001ms
public int GetTotalProvinceCount()
Returns
- int
GetUnownedProvinces(Allocator)
Get unowned provinces (available for colonization) Returns native array that must be disposed by caller Performance target: <5ms for 10k provinces
public NativeArray<ushort> GetUnownedProvinces(Allocator allocator = Allocator.TempJob)
Parameters
allocatorAllocator
Returns
- NativeArray<ushort>
IsOcean(ushort)
Check if province is ocean Performance target: <0.001ms
public bool IsOcean(ushort provinceId)
Parameters
provinceIdushort
Returns
- bool
IsOwned(ushort)
Check if province is owned by any country Performance target: <0.001ms
public bool IsOwned(ushort provinceId)
Parameters
provinceIdushort
Returns
- bool
ResetPerformanceStats()
Reset performance statistics
public static void ResetPerformanceStats()
ShareSameOwner(ushort, ushort)
Check if two provinces are owned by the same country Performance target: <0.01ms
public bool ShareSameOwner(ushort provinceId1, ushort provinceId2)
Parameters
provinceId1ushortprovinceId2ushort
Returns
- bool