Class DiplomacyRelationManager
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
-
objectDiplomacyRelationManager
Fields
DEFAULT_BASE_OPINION
public static readonly FixedPoint64 DEFAULT_BASE_OPINION
Field Value
MAX_OPINION
public static readonly FixedPoint64 MAX_OPINION
Field Value
MIN_OPINION
public static readonly FixedPoint64 MIN_OPINION
Field Value
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
country1ushortcountry2ushortmodifierOpinionModifierrelationsNativeParallelHashMap<ulong, RelationData>allModifiersNativeList<ModifierWithKey>modifierCacheNativeParallelHashMap<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
country1ushortcountry2ushortrelationsNativeParallelHashMap<ulong, RelationData>
Returns
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
countryIDushortthresholdFixedPoint64currentTickintrelationsNativeParallelHashMap<ulong, RelationData>allModifiersNativeList<ModifierWithKey>modifierCacheNativeParallelHashMap<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
countryIDushortthresholdFixedPoint64currentTickintrelationsNativeParallelHashMap<ulong, RelationData>allModifiersNativeList<ModifierWithKey>modifierCacheNativeParallelHashMap<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
country1ushortcountry2ushortcurrentTickintrelationsNativeParallelHashMap<ulong, RelationData>allModifiersNativeList<ModifierWithKey>modifierCacheNativeParallelHashMap<ulong, int>
Returns
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
country1ushortcountry2ushortmodifierTypeIDushortallModifiersNativeList<ModifierWithKey>modifierCacheNativeParallelHashMap<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
country1ushortcountry2ushortbaseOpinionFixedPoint64relationsNativeParallelHashMap<ulong, RelationData>