Struct RelationData
ENGINE LAYER - Hot data for diplomatic relations between two countries
Architecture:
- Fixed-size struct for cache efficiency
- Only stores essential hot data (opinion, war state)
- Cold data (modifiers, history) stored separately
- Stored in sparse Dictionary (only active relationships)
Memory: 16 bytes per relationship
Storage Pattern: Dictionary{(ushort, ushort), RelationData} relations;
- Key: (country1, country2) sorted pair
- Value: this struct
- Only store relationships that exist (sparse)
Example: 1000 countries × 30% interaction = ~30k relationships × 16 bytes = ~480KB
[Serializable]
public struct RelationData
Fields
atWar
Are these countries currently at war?
public bool atWar
Field Value
- bool
baseOpinion
Base opinion value before modifiers (-200 to +200) Cultural/religious similarity, historical relations, etc.
public FixedPoint64 baseOpinion
Field Value
country1
First country in the relationship (lower ID)
public ushort country1
Field Value
- ushort
country2
Second country in the relationship (higher ID)
public ushort country2
Field Value
- ushort
treatyFlags
Treaty flags (bitfield for 8 treaty types) Phase 2: Alliance, NAP, Guarantee×2, MilitaryAccess×2
public byte treatyFlags
Field Value
- byte
Methods
Create(ushort, ushort, FixedPoint64)
Create relationship with base opinion
public static RelationData Create(ushort countryA, ushort countryB, FixedPoint64 baseOpinion)
Parameters
countryAushortcountryBushortbaseOpinionFixedPoint64
Returns
GetOtherCountry(ushort)
Get the other country in this relationship
public ushort GetOtherCountry(ushort countryID)
Parameters
countryIDushort
Returns
- ushort
InvolvesCountry(ushort)
Check if this relationship involves the given country
public bool InvolvesCountry(ushort countryID)
Parameters
countryIDushort
Returns
- bool