Table of Contents

Class DiplomacyRelationManager

Namespace
Core.Diplomacy
Assembly
Core.dll

ENGINE LAYER - Manages opinion calculations and modifiers for diplomatic relations

RESPONSIBILITY:

  • Opinion queries (GetOpinion, GetBaseOpinion)
  • Opinion filtering (GetCountriesWithOpinionAbove/Below)
  • Opinion modifier management (Add/Remove)

PATTERN: Stateless manager (receives data references from DiplomacySystem)

  • Does NOT own NativeCollections (passed as parameters)
  • Pure methods for opinion calculations
  • Zero allocations in hot paths

PERFORMANCE:

  • GetOpinion: O(1) cache lookup + O(m) modifier scan (m = modifiers per relationship, ~10)
  • GetBaseOpinion: O(1) dictionary lookup
  • AddOpinionModifier: O(1) append to flat array
public static class DiplomacyRelationManager
Inheritance
object
DiplomacyRelationManager

Fields

DEFAULT_BASE_OPINION

public static readonly FixedPoint64 DEFAULT_BASE_OPINION

Field Value

FixedPoint64

MAX_OPINION

public static readonly FixedPoint64 MAX_OPINION

Field Value

FixedPoint64

MIN_OPINION

public static readonly FixedPoint64 MIN_OPINION

Field Value

FixedPoint64

Methods

AddOpinionModifier(ushort, ushort, OpinionModifier, NativeParallelHashMap<ulong, RelationData>, NativeList<ModifierWithKey>, NativeParallelHashMap<ulong, int>)

Add opinion modifier to a relationship Modifiers decay over time and affect GetOpinion()

public static void AddOpinionModifier(ushort country1, ushort country2, OpinionModifier modifier, NativeParallelHashMap<ulong, RelationData> relations, NativeList<ModifierWithKey> allModifiers, NativeParallelHashMap<ulong, int> modifierCache)

Parameters

country1 ushort
country2 ushort
modifier OpinionModifier
relations NativeParallelHashMap<ulong, RelationData>
allModifiers NativeList<ModifierWithKey>
modifierCache NativeParallelHashMap<ulong, int>

GetBaseOpinion(ushort, ushort, NativeParallelHashMap<ulong, RelationData>)

Get base opinion (without modifiers) Used for debugging and UI details

public static FixedPoint64 GetBaseOpinion(ushort country1, ushort country2, NativeParallelHashMap<ulong, RelationData> relations)

Parameters

country1 ushort
country2 ushort
relations NativeParallelHashMap<ulong, RelationData>

Returns

FixedPoint64

GetCountriesWithOpinionAbove(ushort, FixedPoint64, int, NativeParallelHashMap<ulong, RelationData>, NativeList<ModifierWithKey>, NativeParallelHashMap<ulong, int>)

Get all countries with opinion above threshold Used by AI for finding potential allies

public static List<ushort> GetCountriesWithOpinionAbove(ushort countryID, FixedPoint64 threshold, int currentTick, NativeParallelHashMap<ulong, RelationData> relations, NativeList<ModifierWithKey> allModifiers, NativeParallelHashMap<ulong, int> modifierCache)

Parameters

countryID ushort
threshold FixedPoint64
currentTick int
relations NativeParallelHashMap<ulong, RelationData>
allModifiers NativeList<ModifierWithKey>
modifierCache NativeParallelHashMap<ulong, int>

Returns

List<ushort>

GetCountriesWithOpinionBelow(ushort, FixedPoint64, int, NativeParallelHashMap<ulong, RelationData>, NativeList<ModifierWithKey>, NativeParallelHashMap<ulong, int>)

Get all countries with opinion below threshold Used by AI for finding war targets

public static List<ushort> GetCountriesWithOpinionBelow(ushort countryID, FixedPoint64 threshold, int currentTick, NativeParallelHashMap<ulong, RelationData> relations, NativeList<ModifierWithKey> allModifiers, NativeParallelHashMap<ulong, int> modifierCache)

Parameters

countryID ushort
threshold FixedPoint64
currentTick int
relations NativeParallelHashMap<ulong, RelationData>
allModifiers NativeList<ModifierWithKey>
modifierCache NativeParallelHashMap<ulong, int>

Returns

List<ushort>

GetOpinion(ushort, ushort, int, NativeParallelHashMap<ulong, RelationData>, NativeList<ModifierWithKey>, NativeParallelHashMap<ulong, int>)

Get total opinion between two countries (base + modifiers) Returns 0 if no relationship exists (neutral) Clamped to [-200, +200]

public static FixedPoint64 GetOpinion(ushort country1, ushort country2, int currentTick, NativeParallelHashMap<ulong, RelationData> relations, NativeList<ModifierWithKey> allModifiers, NativeParallelHashMap<ulong, int> modifierCache)

Parameters

country1 ushort
country2 ushort
currentTick int
relations NativeParallelHashMap<ulong, RelationData>
allModifiers NativeList<ModifierWithKey>
modifierCache NativeParallelHashMap<ulong, int>

Returns

FixedPoint64

RemoveOpinionModifier(ushort, ushort, ushort, NativeList<ModifierWithKey>, NativeParallelHashMap<ulong, int>)

Remove all opinion modifiers of a specific type from a relationship Uses RemoveAtSwapBack for O(1) removal (order not guaranteed)

public static void RemoveOpinionModifier(ushort country1, ushort country2, ushort modifierTypeID, NativeList<ModifierWithKey> allModifiers, NativeParallelHashMap<ulong, int> modifierCache)

Parameters

country1 ushort
country2 ushort
modifierTypeID ushort
allModifiers NativeList<ModifierWithKey>
modifierCache NativeParallelHashMap<ulong, int>

SetBaseOpinion(ushort, ushort, FixedPoint64, NativeParallelHashMap<ulong, RelationData>)

Set base opinion between two countries Creates relationship if it doesn't exist

public static void SetBaseOpinion(ushort country1, ushort country2, FixedPoint64 baseOpinion, NativeParallelHashMap<ulong, RelationData> relations)

Parameters

country1 ushort
country2 ushort
baseOpinion FixedPoint64
relations NativeParallelHashMap<ulong, RelationData>