Table of Contents

Class ProvinceQueries

Namespace
Core.Queries
Assembly
Core.dll

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
object
ProvinceQueries

Constructors

ProvinceQueries(ProvinceSystem, CountrySystem, AdjacencySystem)

public ProvinceQueries(ProvinceSystem provinceSystem, CountrySystem countrySystem, AdjacencySystem adjacencySystem = null)

Parameters

provinceSystem ProvinceSystem
countrySystem CountrySystem
adjacencySystem AdjacencySystem

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

countryId ushort

Dispose()

public void Dispose()

Exists(ushort)

Check if province exists Performance target: <0.001ms

public bool Exists(ushort provinceId)

Parameters

provinceId ushort

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

allocator Allocator

Returns

NativeArray<ushort>

GetCachedProvinceDistance(ushort)

Get province distance from the last CalculateDistancesFromCountry call. Must call CalculateDistancesFromCountry first.

public byte GetCachedProvinceDistance(ushort provinceId)

Parameters

provinceId ushort

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

countryId ushort
allocator Allocator

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

sourceProvinceId ushort
allocator Allocator

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

sourceProvinceId ushort
targetOwnerId ushort
allocator Allocator

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

countryId ushort

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

countryId ushort
allocator Allocator

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

countryId ushort
resultBuffer NativeList<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

province1 ushort
province2 ushort

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

allocator Allocator

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

countryId ushort

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

allocator Allocator

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

provinceId ushort

Returns

ushort

GetPerformanceStats()

Get query performance statistics

public static QueryPerformanceStats GetPerformanceStats()

Returns

QueryPerformanceStats

GetProvinceOwnerColor(ushort)

Get the color of the country that owns this province Performance target: <0.01ms

public Color32 GetProvinceOwnerColor(ushort provinceId)

Parameters

provinceId ushort

Returns

Color32

GetProvinceOwnerTag(ushort)

Get the tag of the country that owns this province Performance target: <0.01ms

public string GetProvinceOwnerTag(ushort provinceId)

Parameters

provinceId ushort

Returns

string

GetProvinceState(ushort)

Get complete province state (8-byte struct) Performance target: <0.001ms

public ProvinceState GetProvinceState(ushort provinceId)

Parameters

provinceId ushort

Returns

ProvinceState

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

ProvinceStatistics

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

countryId ushort
filterOwnerId ushort
allocator Allocator

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

countryId ushort
allocator Allocator

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

tagPattern string
allocator Allocator

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

terrainType ushort
allocator Allocator

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

sourceProvinceId ushort
maxDistance byte
allocator Allocator

Returns

NativeList<ushort>

GetTerrain(ushort)

Get province terrain type (now ushort) Performance target: <0.001ms

public ushort GetTerrain(ushort provinceId)

Parameters

provinceId ushort

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

allocator Allocator

Returns

NativeArray<ushort>

IsOcean(ushort)

Check if province is ocean Performance target: <0.001ms

public bool IsOcean(ushort provinceId)

Parameters

provinceId ushort

Returns

bool

IsOwned(ushort)

Check if province is owned by any country Performance target: <0.001ms

public bool IsOwned(ushort provinceId)

Parameters

provinceId ushort

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

provinceId1 ushort
provinceId2 ushort

Returns

bool