Table of Contents

Class ProvinceSystem

Namespace
Core.Systems
Assembly
Core.dll

Single source of truth for all province data Owns the 8-byte ProvinceState array for deterministic simulation Manages province ownership, development, terrain, and flags Performance: Structure of Arrays design, Burst-compatible, zero allocations

public class ProvinceSystem : MonoBehaviour
Inheritance
object
ProvinceSystem

Properties

Capacity

public int Capacity { get; }

Property Value

int

IsInitialized

public bool IsInitialized { get; }

Property Value

bool

ProvinceCount

public int ProvinceCount { get; }

Property Value

int

Methods

AddHistoricalEvent(ushort, HistoricalEvent)

public void AddHistoricalEvent(ushort provinceId, HistoricalEvent evt)

Parameters

provinceId ushort
evt HistoricalEvent

AddProvince(ushort, ushort)

Add a single province to the system (for runtime colonization)

public void AddProvince(ushort provinceId, ushort terrainType)

Parameters

provinceId ushort
terrainType ushort

ApplyInitialStates(ProvinceInitialStateLoadResult)

Apply initial states (ownership, terrain) from JSON5 data to already-registered provinces Called after InitializeFromDefinitions to set ownership for provinces that have history files

public void ApplyInitialStates(ProvinceInitialStateLoadResult loadResult)

Parameters

loadResult ProvinceInitialStateLoadResult

ApplyResolvedInitialStates(NativeArray<ProvinceInitialState>)

public void ApplyResolvedInitialStates(NativeArray<ProvinceInitialState> initialStates)

Parameters

initialStates NativeArray<ProvinceInitialState>

Dispose()

public void Dispose()

GetAllProvinceIds(Allocator)

public NativeArray<ushort> GetAllProvinceIds(Allocator allocator = Allocator.TempJob)

Parameters

allocator Allocator

Returns

NativeArray<ushort>

GetCountryProvinces(ushort, Allocator)

public NativeArray<ushort> GetCountryProvinces(ushort countryId, Allocator allocator = Allocator.TempJob)

Parameters

countryId ushort
allocator Allocator

Returns

NativeArray<ushort>

GetCountryProvinces(ushort, NativeList<ushort>)

public void GetCountryProvinces(ushort countryId, NativeList<ushort> resultBuffer)

Parameters

countryId ushort
resultBuffer NativeList<ushort>

GetHistoryStats()

public HistoryDatabaseStats GetHistoryStats()

Returns

HistoryDatabaseStats

GetHistorySummary(ushort)

public ProvinceHistorySummary GetHistorySummary(ushort provinceId)

Parameters

provinceId ushort

Returns

ProvinceHistorySummary

GetNativeData()

Get read-only native province data for Burst jobs. Returns a struct with read-only views of province data.

public NativeProvinceData GetNativeData()

Returns

NativeProvinceData

GetProvinceController(ushort)

public ushort GetProvinceController(ushort provinceId)

Parameters

provinceId ushort

Returns

ushort

GetProvinceCountForCountry(ushort)

public int GetProvinceCountForCountry(ushort countryId)

Parameters

countryId ushort

Returns

int

GetProvinceOwner(ushort)

public ushort GetProvinceOwner(ushort provinceId)

Parameters

provinceId ushort

Returns

ushort

GetProvinceState(ushort)

public ProvinceState GetProvinceState(ushort provinceId)

Parameters

provinceId ushort

Returns

ProvinceState

GetProvinceTerrain(ushort)

public ushort GetProvinceTerrain(ushort provinceId)

Parameters

provinceId ushort

Returns

ushort

GetRecentHistory(ushort, int)

public List<HistoricalEvent> GetRecentHistory(ushort provinceId, int maxEvents = 10)

Parameters

provinceId ushort
maxEvents int

Returns

List<HistoricalEvent>

GetStateChecksum()

Calculate checksum of all province states for network sync verification. Used by CommandProcessor for desync detection.

public uint GetStateChecksum()

Returns

uint

GetUIReadBuffer()

Get read-only snapshot buffer for UI access (zero-blocking reads) UI should NEVER write to this buffer - it's one frame behind simulation

public NativeArray<ProvinceState> GetUIReadBuffer()

Returns

NativeArray<ProvinceState>

HasProvince(ushort)

public bool HasProvince(ushort provinceId)

Parameters

provinceId ushort

Returns

bool

Initialize(EventBus)

Initialize the province system with event bus

public void Initialize(EventBus eventBus)

Parameters

eventBus EventBus

InitializeEmpty()

Initialize empty province system for map-only mode No province data loaded - just renders the map texture

public void InitializeEmpty()

InitializeFromDefinitions(List<DefinitionEntry>)

Initialize provinces from definition.csv only (no history data) Creates provinces with default state (no owner, no development)

public void InitializeFromDefinitions(List<DefinitionLoader.DefinitionEntry> definitions)

Parameters

definitions List<DefinitionLoader.DefinitionEntry>

InitializeFromProvinceStates(ProvinceInitialStateLoadResult)

Initialize provinces from JSON5 + Burst loaded province states

public void InitializeFromProvinceStates(ProvinceInitialStateLoadResult loadResult)

Parameters

loadResult ProvinceInitialStateLoadResult

LoadProvinceInitialStates(string)

public void LoadProvinceInitialStates(string dataDirectory)

Parameters

dataDirectory string

LoadProvinceInitialStatesForLinking(string)

public ProvinceInitialStateLoadResult LoadProvinceInitialStatesForLinking(string dataDirectory)

Parameters

dataDirectory string

Returns

ProvinceInitialStateLoadResult

LoadState(BinaryReader)

Load ProvinceSystem state from binary reader Restores: capacity, province states, id mappings Note: Must be called AFTER Initialize() but BEFORE any province operations

public void LoadState(BinaryReader reader)

Parameters

reader BinaryReader

SaveState(BinaryWriter)

Save ProvinceSystem state to binary writer Serializes: capacity, province states, id mappings

public void SaveState(BinaryWriter writer)

Parameters

writer BinaryWriter

SetProvinceOwner(ushort, ushort)

public void SetProvinceOwner(ushort provinceId, ushort newOwner)

Parameters

provinceId ushort
newOwner ushort

SetProvinceState(ushort, ProvinceState)

public void SetProvinceState(ushort provinceId, ProvinceState state)

Parameters

provinceId ushort
state ProvinceState

SetProvinceTerrain(ushort, ushort)

public void SetProvinceTerrain(ushort provinceId, ushort terrain)

Parameters

provinceId ushort
terrain ushort

SwapBuffers()

Called by TimeManager after simulation tick completes Swaps write/read buffers so UI sees latest completed tick

Uses DIRTY TRACKING for efficient partial copies:

  • Only copies provinces that were modified since last swap
  • O(dirty count) instead of O(total provinces)
  • Scales to 100k+ provinces without performance issues
public void SwapBuffers()

SyncBuffersAfterLoad()

Synchronize buffers after scenario loading Ensures both buffers have identical data to prevent first-tick empty buffer bug

public void SyncBuffersAfterLoad()