Table of Contents

Class DiplomacySystem

Namespace
Core.Diplomacy
Assembly
Core.dll

ENGINE LAYER - Facade for diplomatic relations between countries

PATTERN 6: Facade Pattern

  • Owns all NativeCollections (data ownership)
  • Delegates operations to specialized managers (stateless processors)
  • Provides unified API for external systems

ARCHITECTURE:

  • DiplomacyRelationManager: Opinion calculations and modifiers
  • DiplomacyWarManager: War state and declarations
  • DiplomacyTreatyManager: Treaties (Alliance, NAP, Guarantee, Military Access)
  • DiplomacyModifierProcessor: Burst-optimized modifier decay
  • DiplomacySaveLoadHandler: Serialization/deserialization

Performance Targets (Paradox Scale):

  • 1000 countries, 30k active relationships
  • GetOpinion() <0.1ms (O(1) cache + O(m) modifiers)
  • IsAtWar() <0.01ms (HashSet O(1))
  • DecayOpinionModifiers() <5ms for 610k modifiers (Burst parallel)

Pattern Compliance:

  • Pattern 6: Facade (delegates to specialized managers)
  • Pattern 8: Sparse Collections (store active only)
  • Pattern 4: Hot/Cold Separation (RelationData hot, modifiers cold)
  • Pattern 5: Fixed-Point Determinism (FixedPoint64 opinions)
  • Pattern 17: Single Source of Truth (owns all diplomatic state)
public class DiplomacySystem : GameSystem
Inheritance
object
DiplomacySystem
Inherited Members

Properties

SystemName

Unique name for this system (used in logging and debugging)

public override string SystemName { get; }

Property Value

string

Methods

AddOpinionModifier(ushort, ushort, OpinionModifier, int)

public void AddOpinionModifier(ushort country1, ushort country2, OpinionModifier modifier, int currentTick)

Parameters

country1 ushort
country2 ushort
modifier OpinionModifier
currentTick int

AreAllied(ushort, ushort)

public bool AreAllied(ushort country1, ushort country2)

Parameters

country1 ushort
country2 ushort

Returns

bool

BreakAlliance(ushort, ushort, int)

public void BreakAlliance(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

BreakNonAggressionPact(ushort, ushort, int)

public void BreakNonAggressionPact(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

DecayOpinionModifiers(int)

public void DecayOpinionModifiers(int currentTick)

Parameters

currentTick int

DeclareWar(ushort, ushort, int)

public void DeclareWar(ushort attackerID, ushort defenderID, int currentTick)

Parameters

attackerID ushort
defenderID ushort
currentTick int

FormAlliance(ushort, ushort, int)

public void FormAlliance(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

FormNonAggressionPact(ushort, ushort, int)

public void FormNonAggressionPact(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

GetAllWars()

public List<(ushort, ushort)> GetAllWars()

Returns

List<(ushort, ushort)>

GetAllies(ushort)

public List<ushort> GetAllies(ushort countryID)

Parameters

countryID ushort

Returns

List<ushort>

GetAlliesRecursive(ushort)

public HashSet<ushort> GetAlliesRecursive(ushort countryID)

Parameters

countryID ushort

Returns

HashSet<ushort>

GetBaseOpinion(ushort, ushort)

public FixedPoint64 GetBaseOpinion(ushort country1, ushort country2)

Parameters

country1 ushort
country2 ushort

Returns

FixedPoint64

GetCountriesWithOpinionAbove(ushort, FixedPoint64, int)

public List<ushort> GetCountriesWithOpinionAbove(ushort countryID, FixedPoint64 threshold, int currentTick)

Parameters

countryID ushort
threshold FixedPoint64
currentTick int

Returns

List<ushort>

GetCountriesWithOpinionBelow(ushort, FixedPoint64, int)

public List<ushort> GetCountriesWithOpinionBelow(ushort countryID, FixedPoint64 threshold, int currentTick)

Parameters

countryID ushort
threshold FixedPoint64
currentTick int

Returns

List<ushort>

GetEnemies(ushort)

public List<ushort> GetEnemies(ushort countryID)

Parameters

countryID ushort

Returns

List<ushort>

GetGuaranteedBy(ushort)

public List<ushort> GetGuaranteedBy(ushort guaranteedID)

Parameters

guaranteedID ushort

Returns

List<ushort>

GetGuaranteeing(ushort)

public List<ushort> GetGuaranteeing(ushort guarantorID)

Parameters

guarantorID ushort

Returns

List<ushort>

GetOpinion(ushort, ushort, int)

public FixedPoint64 GetOpinion(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

Returns

FixedPoint64

GetStats()

public DiplomacyStats GetStats()

Returns

DiplomacyStats

GetWarCount()

public int GetWarCount()

Returns

int

GrantMilitaryAccess(ushort, ushort, int)

public void GrantMilitaryAccess(ushort granter, ushort recipient, int currentTick)

Parameters

granter ushort
recipient ushort
currentTick int

GuaranteeIndependence(ushort, ushort, int)

public void GuaranteeIndependence(ushort guarantor, ushort guaranteed, int currentTick)

Parameters

guarantor ushort
guaranteed ushort
currentTick int

HasMilitaryAccess(ushort, ushort)

public bool HasMilitaryAccess(ushort granter, ushort recipient)

Parameters

granter ushort
recipient ushort

Returns

bool

HasNonAggressionPact(ushort, ushort)

public bool HasNonAggressionPact(ushort country1, ushort country2)

Parameters

country1 ushort
country2 ushort

Returns

bool

IsAtWar(ushort)

Check if a country is at war with anyone.

public bool IsAtWar(ushort countryID)

Parameters

countryID ushort

Returns

bool

IsAtWar(ushort, ushort)

public bool IsAtWar(ushort country1, ushort country2)

Parameters

country1 ushort
country2 ushort

Returns

bool

IsGuaranteeing(ushort, ushort)

public bool IsGuaranteeing(ushort guarantor, ushort guaranteed)

Parameters

guarantor ushort
guaranteed ushort

Returns

bool

MakePeace(ushort, ushort, int)

public void MakePeace(ushort country1, ushort country2, int currentTick)

Parameters

country1 ushort
country2 ushort
currentTick int

OnInitialize()

Perform system-specific initialization All dependencies guaranteed to be initialized when this is called Override to set up system state, subscribe to events, etc.

protected override void OnInitialize()

OnLoad(SaveGameData)

Load system state from save data Override to deserialize system state for save/load

protected override void OnLoad(SaveGameData saveData)

Parameters

saveData SaveGameData

OnSave(SaveGameData)

Save system state to save data Override to serialize system state for save/load

protected override void OnSave(SaveGameData saveData)

Parameters

saveData SaveGameData

OnShutdown()

Perform system-specific shutdown Override to clean up resources, unsubscribe events, etc.

protected override void OnShutdown()

RemoveOpinionModifier(ushort, ushort, ushort)

public void RemoveOpinionModifier(ushort country1, ushort country2, ushort modifierTypeID)

Parameters

country1 ushort
country2 ushort
modifierTypeID ushort

RevokeGuarantee(ushort, ushort, int)

public void RevokeGuarantee(ushort guarantor, ushort guaranteed, int currentTick)

Parameters

guarantor ushort
guaranteed ushort
currentTick int

RevokeMilitaryAccess(ushort, ushort, int)

public void RevokeMilitaryAccess(ushort granter, ushort recipient, int currentTick)

Parameters

granter ushort
recipient ushort
currentTick int

SetBaseOpinion(ushort, ushort, FixedPoint64)

public void SetBaseOpinion(ushort country1, ushort country2, FixedPoint64 baseOpinion)

Parameters

country1 ushort
country2 ushort
baseOpinion FixedPoint64