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
-
objectEconomySystem
Constructors
EconomySystem(GameState, PlayerState, ModifierSystem, bool)
Create a new EconomySystem.
public EconomySystem(GameState gameStateRef, PlayerState playerStateRef, ModifierSystem modifierSystemRef, bool log = true)
Parameters
gameStateRefGameStateReference to the game state.
playerStateRefPlayerStateReference to player state for identifying player country.
modifierSystemRefModifierSystemModifier system for building bonuses.
logboolWhether 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
Methods
AddGold(int)
Add gold to player (for commands/cheats)
public void AddGold(int amount)
Parameters
amountint
AddGoldToCountry(ushort, FixedPoint64)
Add gold to a specific country (FixedPoint64 version for precise calculations)
public void AddGoldToCountry(ushort countryId, FixedPoint64 amount)
Parameters
countryIdushortamountFixedPoint64
AddGoldToCountry(ushort, int)
Add gold to a specific country (int version for simple cases)
public void AddGoldToCountry(ushort countryId, int amount)
Parameters
countryIdushortamountint
Deserialize(byte[])
Deserialize economy state from byte array. Restores FixedPoint64 from raw long values.
public void Deserialize(byte[] data)
Parameters
databyte[]
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
countryIdushort
Returns
GetCountryGoldInt(ushort)
Get gold for a specific country as int (for simple display).
public int GetCountryGoldInt(ushort countryId)
Parameters
countryIdushort
Returns
- int
GetMonthlyIncome(ushort)
Get monthly income for a country (cached, using ModifierSystem)
public FixedPoint64 GetMonthlyIncome(ushort countryId)
Parameters
countryIdushort
Returns
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
countryIdushort
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
countryIdushort
RemoveGold(int)
Remove gold from player (returns false if insufficient)
public bool RemoveGold(int amount)
Parameters
amountint
Returns
- bool
RemoveGoldFromCountry(ushort, FixedPoint64)
Remove gold from a specific country (returns false if insufficient)
public bool RemoveGoldFromCountry(ushort countryId, FixedPoint64 amount)
Parameters
countryIdushortamountFixedPoint64
Returns
- bool
RemoveGoldFromCountry(ushort, int)
Remove gold from a specific country (int version for simple cases)
public bool RemoveGoldFromCountry(ushort countryId, int amount)
Parameters
countryIdushortamountint
Returns
- bool
Serialize()
Serialize economy state to byte array. FixedPoint64 uses its RawValue (long) for deterministic serialization.
public byte[] Serialize()
Returns
- byte[]