Table of Contents

Class EconomySystem

Namespace
StarterKit
Assembly
StarterKit.dll

Simple economy for StarterKit. 1 gold per province + modifier bonuses, collected monthly. Tracks gold for ALL countries (for ledger display).

Uses FixedPoint64 for deterministic calculations across all platforms. This ensures multiplayer sync - float operations produce different results on different CPUs, but FixedPoint64 is identical everywhere.

Income Formula (per province): baseIncome = 1 gold localModified = baseIncome * (1 + LocalIncomeModifier) finalIncome = localModified * (1 + CountryIncomeModifier)

public class EconomySystem
Inheritance
object
EconomySystem

Constructors

EconomySystem(GameState, PlayerState, ModifierSystem, bool)

Create a new EconomySystem.

public EconomySystem(GameState gameStateRef, PlayerState playerStateRef, ModifierSystem modifierSystemRef, bool log = true)

Parameters

gameStateRef GameState

Reference to the game state.

playerStateRef PlayerState

Reference to player state for identifying player country.

modifierSystemRef ModifierSystem

Modifier system for building bonuses.

log bool

Whether to log income collection.

Properties

Gold

Player's gold (convenience property, returns int for simple display)

public int Gold { get; }

Property Value

int

GoldFixed

Player's gold as FixedPoint64 (for precise calculations)

public FixedPoint64 GoldFixed { get; }

Property Value

FixedPoint64

Methods

AddGold(int)

Add gold to player (for commands/cheats)

public void AddGold(int amount)

Parameters

amount int

AddGoldToCountry(ushort, FixedPoint64)

Add gold to a specific country (FixedPoint64 version for precise calculations)

public void AddGoldToCountry(ushort countryId, FixedPoint64 amount)

Parameters

countryId ushort
amount FixedPoint64

AddGoldToCountry(ushort, int)

Add gold to a specific country (int version for simple cases)

public void AddGoldToCountry(ushort countryId, int amount)

Parameters

countryId ushort
amount int

Deserialize(byte[])

Deserialize economy state from byte array. Restores FixedPoint64 from raw long values.

public void Deserialize(byte[] data)

Parameters

data byte[]

Dispose()

public void Dispose()

GetCountriesWithGold()

Get all countries with tracked gold (for ledger)

public IEnumerable<ushort> GetCountriesWithGold()

Returns

IEnumerable<ushort>

GetCountryGold(ushort)

Get gold for a specific country as FixedPoint64.

public FixedPoint64 GetCountryGold(ushort countryId)

Parameters

countryId ushort

Returns

FixedPoint64

GetCountryGoldInt(ushort)

Get gold for a specific country as int (for simple display).

public int GetCountryGoldInt(ushort countryId)

Parameters

countryId ushort

Returns

int

GetMonthlyIncome(ushort)

Get monthly income for a country (cached, using ModifierSystem)

public FixedPoint64 GetMonthlyIncome(ushort countryId)

Parameters

countryId ushort

Returns

FixedPoint64

GetMonthlyIncomeInt()

Get monthly income for player (convenience)

public int GetMonthlyIncomeInt()

Returns

int

GetMonthlyIncomeInt(ushort)

Get monthly income for a country as int (for simple display)

public int GetMonthlyIncomeInt(ushort countryId)

Parameters

countryId ushort

Returns

int

InvalidateAllIncome()

Invalidate all income caches. Call after load or major changes.

public void InvalidateAllIncome()

InvalidateCountryIncome(ushort)

Invalidate income cache for a specific country. Call when buildings change or modifiers are added/removed.

public void InvalidateCountryIncome(ushort countryId)

Parameters

countryId ushort

RemoveGold(int)

Remove gold from player (returns false if insufficient)

public bool RemoveGold(int amount)

Parameters

amount int

Returns

bool

RemoveGoldFromCountry(ushort, FixedPoint64)

Remove gold from a specific country (returns false if insufficient)

public bool RemoveGoldFromCountry(ushort countryId, FixedPoint64 amount)

Parameters

countryId ushort
amount FixedPoint64

Returns

bool

RemoveGoldFromCountry(ushort, int)

Remove gold from a specific country (int version for simple cases)

public bool RemoveGoldFromCountry(ushort countryId, int amount)

Parameters

countryId ushort
amount int

Returns

bool

Serialize()

Serialize economy state to byte array. FixedPoint64 uses its RawValue (long) for deterministic serialization.

public byte[] Serialize()

Returns

byte[]