Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ jobs:
--exclude='docs/' \
--exclude='*.csproj' \
--exclude='*.sln' \
--exclude='.coderabbit.yaml' \
--exclude='.pre-commit-config.yaml' \
--exclude='INTRODUCTION.txt' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='*.md' \
Expand Down
70 changes: 69 additions & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,75 @@
<li>1.6</li>
<li>1.7</li>
</supportedVersions>
<description>AI-driven dialogue system for RimWorld colonists. Intercepts game events to generate contextual AI responses, injects dialogue Thoughts, and allows player-initiated conversations. [v2.0 BREAKING CHANGES]</description>
<description>[h1]RimMind - Dialogue (v2.0)[/h1]
Contextual social dialogue, native spoken ToolCalls, and overhead speech bubble system for RimWorld colonists. Powered by the structured [code]express_dialogue[/code] function-calling pipeline, colonists converse naturally during dining, work shifts, recreation, and crisis moments—dynamically shaping moods and interpersonal relationships.

[b]v2.0 Clean Architecture &amp; RimWorld 1.6 / 1.7 Dual-Version Support:[/b]
[list]
[*][b]RimWorld 1.6 &amp; 1.7 (Waylith / .NET 10) Ready[/b]: Native multi-target compilation supporting both RimWorld 1.6 (.NET Framework 4.8) and RimWorld 1.7 (.NET 10 / Harmony 2.x &amp; 3.x).
[*][b]v2.0 Native [code]express_dialogue[/code] ToolCall Pipeline[/b]: Transmits spoken lines ([code]reply[/code]), inner psychological subtext ([code]thought[/code]), and relationship delta ([code]relation_delta[/code]) as structured tool calls. Note: v1.x saves are not compatible with v2.0.
[*][b]Multi-Stage Anti-Pollution Sanitizer[/b]: [code]DialogueTextSanitizer[/code] strips [code]think[/code] reasoning blocks, code fences, and raw JSON fragments so overhead speech bubbles remain 100% clean and immersive.
[/list]

[h2]What Is RimMind[/h2]
RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with Large Language Models (LLM), it transforms colonists into self-reflecting agents with distinct personalities, three-tier memories, natural spoken dialogues, autonomous mechanisms, and dynamic storytelling.

[h2]Sub-mod List &amp; Dependency Relationships[/h2]
[table]
[tr][th]Mod[/th][th]Responsibility[/th][th]Dependencies[/th][th]GitHub[/th][/tr]
[tr][td]RimMind-Core[/td][td]LLM runtime, 4-Zone context engine, async queue, ToolCall registry &amp; F8 Hub[/td][td]Harmony[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core]Link[/url][/td][/tr]
[tr][td]RimMind-Actions[/td][td]Composite ToolCall mechanisms, battlefield triage &amp; autonomous construction[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Actions]Link[/url][/td][/tr]
[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy &amp; player approval[/td][td]Core, Actions[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Advisor]Link[/url][/td][/tr]
[tr][td][b]RimMind-Dialogue[/b][/td][td]Contextual spoken dialogue via express_dialogue ToolCall &amp; speech bubbles[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Dialogue]Link[/url][/td][/tr]
[tr][td]RimMind-Memory[/td][td]3-Tier cognitive memory hierarchy, work aggregation &amp; temporal decay[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Memory]Link[/url][/td][/tr]
[tr][td]RimMind-Personality[/td][td]Big-Five psychological profiles, dawn monologues &amp; dynamic mood thoughts[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Personality]Link[/url][/td][/tr]
[tr][td]RimMind-Storyteller[/td][td]AI Story Director, dramatic tension curve, chained arcs &amp; Storyteller Altar[/td][td]Core, Memory[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Storyteller]Link[/url][/td][/tr]
[tr][td]RimMind-Extension-ModelService[/td][td]Multi-provider routing, Anthropic KV cache, local gateways &amp; load balancing[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Extension-ModelService]Link[/url][/td][/tr]
[tr][td]RimMind-Bridge-RimChat[/td][td]RimChat compatibility bridge: dialogue/action mutual exclusion &amp; context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr]
[tr][td]RimMind-Bridge-RimTalk[/td][td]RimTalk compatibility bridge: bubble harmonization &amp; bidirectional context[/td][td]Core, RimTalk[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimTalk]Link[/url][/td][/tr]
[/table]
[code]Core ──┬── Actions ── Advisor
├── Dialogue
├── Memory ── Storyteller
├── Personality
├── Extension-ModelService
├── Bridge-RimChat
└── Bridge-RimTalk[/code]

[h2]Core Features[/h2]
[list]
[*][b]Event-Responsive &amp; Proximity Banter[/b] - Replaces vanilla Chitchat and DeepTalk with context-aware AI conversations when awake colonists are within 6.9 tiles during dining, crafting, or relaxation, plus monologues on injuries, skill milestones, and mood swings.
[*][b]Player-Initiated Multi-Turn Chat[/b] - Start direct conversations via pawn Gizmo buttons or right-click menus with persistent session memory.
[*][b]Dynamic Relationship &amp; Thought Injection[/b] - Conversations apply real-time social opinion modifiers (-5 to +5) and inject emotional Thoughts ([i]ENCOURAGED, VALUED, CONNECTED, HURT, STRESSED, IRRITATED[/i]) that affect colonist mood and notify [code]RimMind-Advisor[/code].
[*][b]Strict Liveness &amp; Consciousness Gating[/b] - Guarded by [code]RimMindPawnLookup[/code] so sleeping, downed, dead, imprisoned, or off-map pawns never emit ghost dialogues.
[*][b]Draggable Floating Chat HUD &amp; History Log[/b] - Real-time corner dialogue overlay with adjustable opacity, plus a categorized dual-panel conversation log window.
[/list]

[h2]Trigger Scenarios[/h2]
[table]
[tr][th]Trigger Source[/th][th]Description[/th][th]Interaction Type[/th][/tr]
[tr][td]Social Interaction[/td][td]Overrides vanilla Chitchat &amp; DeepTalk between nearby awake colonists[/td][td]Two-Party Dialogue &amp; Reply Chain[/td][/tr]
[tr][td]Health &amp; Injury[/td][td]Reacts to combat wounds, illnesses, or recovery[/td][td]Personal Monologue[/td][/tr]
[tr][td]Skill Milestones[/td][td]Celebrates or reflects on skill level upgrades[/td][td]Personal Monologue[/td][/tr]
[tr][td]Mood Fluctuations[/td][td]Reacts when mood shifts exceed configured threshold[/td][td]Personal Monologue[/td][/tr]
[tr][td]Player Manual Chat[/td][td]Initiated via pawn Gizmo or right-click menu[/td][td]Multi-Turn Interactive Chat[/td][/tr]
[/table]

[h2]Thought Tags &amp; Mood Impacts[/h2]
[table]
[tr][th]Tag[/th][th]Mood Offset[/th][th]Description[/th][/tr]
[tr][td]VALUED / CONNECTED[/td][td]+2[/td][td]Feeling appreciated and emotionally close to companions[/td][/tr]
[tr][td]ENCOURAGED[/td][td]+1[/td][td]Reassured by supportive words[/td][/tr]
[tr][td]HURT / IRRITATED[/td][td]-1[/td][td]Stung or annoyed by friction in conversation[/td][/tr]
[tr][td]STRESSED[/td][td]-2[/td][td]Weighed down by tense exchanges[/td][/tr]
[/table]

[h2]Frequently Asked Questions[/h2]
[b]Q: Will dialogues slow down the game?[/b]
A: No. Requests run asynchronously in the background with per-pawn and per-pair cooldowns.

[b]Q: Does it conflict with RimTalk or RimChat?[/b]
A: Use [code]RimMind-Bridge-RimTalk[/code] or [code]RimMind-Bridge-RimChat[/code] for automatic mutual exclusion gating and unified bubble rendering.</description>
<modDependencies>
<li>
<packageId>brrainz.harmony</packageId>
Expand Down
74 changes: 33 additions & 41 deletions Source/Comps/CompRimMindDialogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
{
private int _lastTriggerTick = -99999;

private Pawn Pawn => (Pawn)parent;
private Pawn? PawnOrNull => parent as Pawn;
private Pawn? Pawn => parent as Pawn;

public override void CompTick()
{
base.CompTick();
if (!Pawn.IsColonist) return;
if (parent is not Pawn pawn || !pawn.IsColonist) return;
var settings = RimMindDialogueSettings.Get();
if (!settings.enabled || !settings.autoDialogueEnabled) return;
// Sample natural encounters every 250 ticks (≈4 seconds)
if (!Pawn.IsHashIntervalTick(250)) return;
// Sample natural encounters every 250 ticks (~4 seconds)
if (!pawn.IsHashIntervalTick(250)) return;
if (!RimMindAPI.IsConfigured()) return;

Check warning on line 27 in Source/Comps/CompRimMindDialogue.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.IsConfigured()' is obsolete: 'Use RimMindAPI.Settings.IsConfigured instead.'

Check warning on line 27 in Source/Comps/CompRimMindDialogue.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.IsConfigured()' is obsolete: 'Use RimMindAPI.Settings.IsConfigured instead.'
if (!IsEligible()) return;

int currentTick = Find.TickManager.TicksGame;
Expand All @@ -39,69 +40,69 @@
if (nearbyCompanion != null)
{
// Dining Encounter (Shared Meal)
if (Pawn.CurJob?.def == JobDefOf.Ingest && nearbyCompanion.CurJob?.def == JobDefOf.Ingest)
if (pawn.CurJob?.def == JobDefOf.Ingest && nearbyCompanion.CurJob?.def == JobDefOf.Ingest)
{
float dynamicChance = CalculateDynamicSocialChance(settings.diningSocialChance, Pawn, nearbyCompanion, activityScale);
float dynamicChance = CalculateDynamicSocialChance(settings.diningSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableDiningSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.DiningEncounter".Translate(nearbyCompanion.LabelShort);
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}

// Recreation Encounter (Shared Play / Joy)
if (Pawn.CurJob?.def?.joyKind != null && nearbyCompanion.CurJob?.def?.joyKind != null)
if (pawn.CurJob?.def?.joyKind != null && nearbyCompanion.CurJob?.def?.joyKind != null)
{
float dynamicChance = CalculateDynamicSocialChance(settings.recreationSocialChance, Pawn, nearbyCompanion, activityScale);
float dynamicChance = CalculateDynamicSocialChance(settings.recreationSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableRecreationSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.RecreationEncounter".Translate(nearbyCompanion.LabelShort);
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}

// Co-working Encounter (Working side-by-side)
if (Pawn.CurJob != null && nearbyCompanion.CurJob != null)
if (pawn.CurJob != null && nearbyCompanion.CurJob != null)
{
if (!IsIdleOrResting(Pawn.CurJob.def) && !IsIdleOrResting(nearbyCompanion.CurJob.def)
&& Pawn.CurJob.def != JobDefOf.Ingest && nearbyCompanion.CurJob.def != JobDefOf.Ingest
&& Pawn.CurJob.def?.joyKind == null && nearbyCompanion.CurJob.def?.joyKind == null)
if (!IsIdleOrResting(pawn.CurJob.def) && !IsIdleOrResting(nearbyCompanion.CurJob.def)
&& pawn.CurJob.def != JobDefOf.Ingest && nearbyCompanion.CurJob.def != JobDefOf.Ingest
&& pawn.CurJob.def?.joyKind == null && nearbyCompanion.CurJob.def?.joyKind == null)
{
float dynamicChance = CalculateDynamicSocialChance(settings.coworkerSocialChance, Pawn, nearbyCompanion, activityScale);
float dynamicChance = CalculateDynamicSocialChance(settings.coworkerSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableCoworkerSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.CoworkerEncounter".Translate(nearbyCompanion.LabelShort);
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}
}
}
else
{
float mood = Pawn.needs?.mood?.CurLevel ?? 0.5f;
float mood = pawn.needs?.mood?.CurLevel ?? 0.5f;
float jitter = Rand.Range(0.85f, 1.15f);

// Solitary contemplation & recreation monologue
if (Pawn.CurJobDef?.defName == "Skygaze" || Pawn.CurJobDef?.defName == "Meditate")
if (pawn.CurJobDef?.defName == "Skygaze" || pawn.CurJobDef?.defName == "Meditate")
{
float monologueChance = 0.35f * (mood > 0.8f || mood < 0.3f ? 1.25f : 1.0f) * jitter * activityScale;
if (settings.autoDialogueEnabled && Rand.Value < monologueChance)
{
string contextMsg = "RimMind.Dialogue.Context.ContemplationMonologue".Translate();
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
return;
}
}
else if (Pawn.CurJob?.def?.joyKind != null)
else if (pawn.CurJob?.def?.joyKind != null)
{
float monologueChance = (settings.recreationSocialChance * 0.4f) * jitter * activityScale;
if (settings.autoDialogueEnabled && Rand.Value < monologueChance)
{
string contextMsg = "RimMind.Dialogue.Context.RecreationMonologue".Translate();
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
return;
}
}
Expand All @@ -113,45 +114,33 @@
if (settings.autoDialogueEnabled && (currentTick - _lastTriggerTick >= idleCooldown))
{
string contextMsg = "RimMind.Dialogue.Context.IdleState".Translate();
TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
}
}

/// <summary>
/// Dynamically adjusts base social encounter chance according to:
/// 1. Inter-pawn social opinion (-100 to +100).
/// 2. Romantic relationship status (lovers/spouses communicate significantly more often).
/// 3. Speaker's emotional state (cheerfulness vs deep depression).
/// 4. Organic ±15% natural daily jitter.
/// 5. Global ActivityFrequencyScale setting multiplier.
/// </summary>
public static float CalculateDynamicSocialChance(float baseChance, Pawn speaker, Pawn listener, float activityScale = 1.0f)
{
float chance = baseChance * activityScale;

// 1. Social relations & opinion modifier (-100 to +100)
if (speaker.relations != null && listener != null)
{
int opinion = speaker.relations.OpinionOf(listener);
float opinionMod = 1.0f + (opinion / 200f);
chance *= Mathf.Clamp(opinionMod, 0.30f, 1.60f);

// Romantic partner boost (+40%)
if (LovePartnerRelationUtility.LovePartnerRelationExists(speaker, listener))
{
chance *= 1.4f;
}
}

// 2. Speaker mood modifier (happy colonists are more communicative)
if (speaker.needs?.mood != null)
{
float mood = speaker.needs.mood.CurLevel;
if (mood > 0.75f) chance *= 1.20f;
else if (mood < 0.25f) chance *= 0.65f;
}

// 3. Organic jitter (±15% natural variance)
float jitter = Rand.Range(0.85f, 1.15f);
chance *= jitter;

Expand Down Expand Up @@ -202,14 +191,15 @@

private Pawn? FindNearbyCompanion()
{
Map? map = Pawn.Map;
if (PawnOrNull is not Pawn pawn) return null;
Map? map = pawn.Map;
var spawnedColonists = map?.mapPawns?.FreeColonistsSpawned;
if (spawnedColonists == null) return null;

for (int i = 0; i < spawnedColonists.Count; i++)
{
Pawn other = spawnedColonists[i];
if (other != null && other != Pawn && RimMindPawnLookup.IsEligibleColonist(other) && RestUtility.Awake(other) && Pawn.Position.InHorDistOf(other.Position, 6.9f))
if (other != null && other != pawn && RimMindPawnLookup.IsEligibleColonist(other) && RestUtility.Awake(other) && pawn.Position.InHorDistOf(other.Position, 6.9f))
{
return other;
}
Expand All @@ -219,6 +209,7 @@

public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
if (PawnOrNull is not Pawn pawn) yield break;
if (!IsEligible()) yield break;
if (!RimMindDialogueSettings.Get().enabled) yield break;
if (!RimMindDialogueSettings.Get().playerDialogueEnabled) yield break;
Expand All @@ -229,7 +220,7 @@
? "RimMind.Dialogue.UI.Gizmo.ChatWith".Translate(parent.LabelShort).ToString()
: $"Chat with {parent.LabelShort}",
icon = ContentFinder<Texture2D>.Get("UI/RimMindDialogue_Icon", reportFailure: false),
action = () => Find.WindowStack.Add(new Window_Dialogue((Pawn)parent))
action = () => Find.WindowStack.Add(new Window_Dialogue(pawn))
};
}

Expand All @@ -241,10 +232,11 @@

private bool IsEligible()
{
return RimMindPawnLookup.IsEligibleColonist(Pawn)
&& RestUtility.Awake(Pawn)
&& !(Pawn.drafter?.Drafted ?? false)
&& Pawn.needs?.mood != null;
return PawnOrNull is Pawn pawn
&& RimMindPawnLookup.IsEligibleColonist(pawn)
&& RestUtility.Awake(pawn)
&& !(pawn.drafter?.Drafted ?? false)
&& pawn.needs?.mood != null;
}
}
}
1 change: 1 addition & 0 deletions Source/Core/DialogueRequestCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@
return "Dialogue participant is unavailable.";
if (recipient != null && (!RimMind.Presentation.Api.RimMindPawnLookup.IsActiveSpawnedColonist(recipient) || recipient.Downed))
return "Dialogue recipient is unavailable.";
if (!RimMindAPI.IsConfigured())

Check warning on line 110 in Source/Core/DialogueRequestCoordinator.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.IsConfigured()' is obsolete: 'Use RimMindAPI.Settings.IsConfigured instead.'

Check warning on line 110 in Source/Core/DialogueRequestCoordinator.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.IsConfigured()' is obsolete: 'Use RimMindAPI.Settings.IsConfigured instead.'
return "AI is not configured.";
if (!_activityState.IsReady(settings, currentTick))
return "Dialogue startup delay is active.";
if (_reservations.IsPawnPending(pawn.thingIDNumber))
return "A dialogue request is already pending for this pawn.";
if (RimMindAPI.ShouldSkipDialogue(pawn, ToTriggerKind(type)))

Check warning on line 116 in Source/Core/DialogueRequestCoordinator.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.ShouldSkipDialogue(Pawn, string)' is obsolete: 'Use RimMindAPI.Ext.ShouldSkipDialogue instead.'

Check warning on line 116 in Source/Core/DialogueRequestCoordinator.cs

View workflow job for this annotation

GitHub Actions / test / test

'RimMindAPI.ShouldSkipDialogue(Pawn, string)' is obsolete: 'Use RimMindAPI.Ext.ShouldSkipDialogue instead.'
return "AI dialogue condition is not met.";

if (DialogueFlowPolicy.UsesMonologueCooldown(
Expand Down Expand Up @@ -300,6 +300,7 @@
.WithToolDispatchMode(ToolCallDispatchMode.Manual)
.WithMaxTokens(800)
.WithTemperature(type == DialogueTriggerType.PlayerInput ? 0.85f : 0.8f)
.WithReasoningEffort(ReasoningEffort.None)
.WithCancellation(lifetime.Token);
if (!string.IsNullOrEmpty(speakerName))
{
Expand Down
Loading
Loading