diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index 2f4b62b8..fc5c71dd 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_GetColonistStatus.cs b/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_GetColonistStatus.cs index a51517b5..50e76924 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_GetColonistStatus.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_GetColonistStatus.cs @@ -10,134 +10,83 @@ namespace WulaFallenEmpire.EventSystem.AI.Tools public class Tool_GetColonistStatus : AITool { public override string Name => "get_colonist_status"; - public override string Description => "Returns detailed status of all colonists, including needs (hunger, rest, etc.) and health conditions (injuries, diseases). Use this to verify player claims about their situation (e.g., 'we are starving')."; - public override string UsageSchema => "{}"; + public override string Description => "Returns detailed status of colonists. Can be filtered to find the colonist in the worst condition (e.g., lowest mood, most injured). This helps the AI understand the colony's state without needing to know specific names."; + public override string UsageSchema => "{'filter': 'string (optional, can be 'lowest_mood', 'most_injured', 'hungriest', 'most_tired')'}"; public override string Execute(string args) { try { - StringBuilder sb = new StringBuilder(); - List colonists = new List(); - - // Manually collect colonists from all maps to be safe + string filter = null; + if (!string.IsNullOrEmpty(args)) + { + var json = SimpleJsonParser.Parse(args); + if (json != null && json.TryGetValue("filter", out var filterObj) && filterObj is string filterStr) + { + filter = filterStr.ToLower(); + } + } + + List allColonists = new List(); if (Find.Maps != null) { foreach (var map in Find.Maps) { if (map.mapPawns != null) { - colonists.AddRange(map.mapPawns.FreeColonists); + allColonists.AddRange(map.mapPawns.FreeColonists); } } } - if (colonists.Count == 0) + if (allColonists.Count == 0) { return "No active colonists found."; } - sb.AppendLine($"Found {colonists.Count} colonists:"); + List colonistsToReport = new List(); - foreach (var pawn in colonists) + if (string.IsNullOrEmpty(filter)) { - if (pawn == null) continue; - sb.AppendLine($"- {pawn.Name.ToStringShort} ({pawn.def.label}, Age {pawn.ageTracker.AgeBiologicalYears}):"); - - // Needs - if (pawn.needs != null) + colonistsToReport.AddRange(allColonists); + } + else + { + Pawn targetPawn = null; + switch (filter) { - sb.Append(" Needs: "); - bool anyNeedLow = false; - foreach (var need in pawn.needs.AllNeeds) - { - if (need.CurLevelPercentage < 0.3f) // Report low needs - { - sb.Append($"{need.LabelCap} ({need.CurLevelPercentage:P0}), "); - anyNeedLow = true; - } - } - if (!anyNeedLow) sb.Append("All needs satisfied. "); - else sb.Length -= 2; // Remove trailing comma - sb.AppendLine(); + case "lowest_mood": + targetPawn = allColonists.Where(p => p.needs?.mood != null).OrderBy(p => p.needs.mood.CurLevelPercentage).FirstOrDefault(); + break; + case "most_injured": + targetPawn = allColonists.Where(p => p.health?.summaryHealth != null).OrderBy(p => p.health.summaryHealth.SummaryHealthPercent).FirstOrDefault(); + break; + case "hungriest": + targetPawn = allColonists.Where(p => p.needs?.food != null).OrderBy(p => p.needs.food.CurLevelPercentage).FirstOrDefault(); + break; + case "most_tired": + targetPawn = allColonists.Where(p => p.needs?.rest != null).OrderBy(p => p.needs.rest.CurLevelPercentage).FirstOrDefault(); + break; } + if (targetPawn != null) + { + colonistsToReport.Add(targetPawn); + } + } - // Health - if (pawn.health != null) - { - sb.Append(" Health: "); - var hediffs = pawn.health.hediffSet.hediffs; - if (hediffs != null && hediffs.Count > 0) - { - var visibleHediffs = new List(); - foreach(var h in hediffs) - { - if(h.Visible) visibleHediffs.Add(h); - } + if (colonistsToReport.Count == 0) + { + return string.IsNullOrEmpty(filter) ? "No active colonists found." : $"No colonist found for filter '{filter}'. This could be because all colonists are healthy or their needs are met."; + } - if (visibleHediffs.Count > 0) - { - foreach (var h in visibleHediffs) - { - string severity = h.SeverityLabel; - if (!string.IsNullOrEmpty(severity)) severity = $" ({severity})"; - sb.Append($"{h.LabelCap}{severity}, "); - } - if (sb.Length >= 2) sb.Length -= 2; - } - else - { - sb.Append("Healthy."); - } - } - else - { - sb.Append("Healthy."); - } - - // Bleeding - if (pawn.health.hediffSet.BleedRateTotal > 0.01f) - { - sb.Append($" [Bleeding: {pawn.health.hediffSet.BleedRateTotal:P0}/day]"); - } - sb.AppendLine(); - } - - // Mood - if (pawn.needs?.mood != null) - { - sb.AppendLine($" Mood: {pawn.needs.mood.CurLevelPercentage:P0} ({pawn.needs.mood.MoodString})"); - } + StringBuilder sb = new StringBuilder(); + sb.AppendLine(string.IsNullOrEmpty(filter) + ? $"Found {colonistsToReport.Count} colonists:" + : $"Reporting on colonist with {filter.Replace("_", " ")}:"); - // Equipment - if (pawn.equipment?.Primary != null) - { - sb.AppendLine($" Weapon: {pawn.equipment.Primary.LabelCap}"); - } - - // Apparel - if (pawn.apparel?.WornApparelCount > 0) - { - sb.Append(" Apparel: "); - foreach (var apparel in pawn.apparel.WornApparel) - { - sb.Append($"{apparel.LabelCap}, "); - } - sb.Length -= 2; // Remove trailing comma - sb.AppendLine(); - } - - // Inventory - if (pawn.inventory != null && pawn.inventory.innerContainer.Count > 0) - { - sb.Append(" Inventory: "); - foreach (var item in pawn.inventory.innerContainer) - { - sb.Append($"{item.LabelCap}, "); - } - sb.Length -= 2; // Remove trailing comma - sb.AppendLine(); - } + foreach (var pawn in colonistsToReport) + { + AppendPawnStatus(sb, pawn); } return sb.ToString(); @@ -147,5 +96,102 @@ namespace WulaFallenEmpire.EventSystem.AI.Tools return $"Error: {ex.Message}"; } } + + private void AppendPawnStatus(StringBuilder sb, Pawn pawn) + { + if (pawn == null) return; + sb.AppendLine($"- {pawn.Name.ToStringShort} ({pawn.def.label}, Age {pawn.ageTracker.AgeBiologicalYears}):"); + + // Needs + if (pawn.needs != null) + { + sb.Append(" Needs: "); + bool anyNeedLow = false; + foreach (var need in pawn.needs.AllNeeds) + { + if (need.CurLevelPercentage < 0.3f) // Report low needs + { + sb.Append($"{need.LabelCap} ({need.CurLevelPercentage:P0}), "); + anyNeedLow = true; + } + } + if (!anyNeedLow) sb.Append("All needs satisfied. "); + else sb.Length -= 2; // Remove trailing comma + sb.AppendLine(); + } + + // Health + if (pawn.health != null) + { + sb.Append(" Health: "); + var hediffs = pawn.health.hediffSet.hediffs; + if (hediffs != null && hediffs.Count > 0) + { + var visibleHediffs = hediffs.Where(h => h.Visible).ToList(); + + if (visibleHediffs.Count > 0) + { + foreach (var h in visibleHediffs) + { + string severity = h.SeverityLabel; + if (!string.IsNullOrEmpty(severity)) severity = $" ({severity})"; + sb.Append($"{h.LabelCap}{severity}, "); + } + sb.Length -= 2; + } + else + { + sb.Append("Healthy."); + } + } + else + { + sb.Append("Healthy."); + } + + // Bleeding + if (pawn.health.hediffSet.BleedRateTotal > 0.01f) + { + sb.Append($" [Bleeding: {pawn.health.hediffSet.BleedRateTotal:P0}/day]"); + } + sb.AppendLine(); + } + + // Mood + if (pawn.needs?.mood != null) + { + sb.AppendLine($" Mood: {pawn.needs.mood.CurLevelPercentage:P0} ({pawn.needs.mood.MoodString})"); + } + + // Equipment + if (pawn.equipment?.Primary != null) + { + sb.AppendLine($" Weapon: {pawn.equipment.Primary.LabelCap}"); + } + + // Apparel + if (pawn.apparel?.WornApparelCount > 0) + { + sb.Append(" Apparel: "); + foreach (var apparel in pawn.apparel.WornApparel) + { + sb.Append($"{apparel.LabelCap}, "); + } + sb.Length -= 2; // Remove trailing comma + sb.AppendLine(); + } + + // Inventory + if (pawn.inventory != null && pawn.inventory.innerContainer.Count > 0) + { + sb.Append(" Inventory: "); + foreach (var item in pawn.inventory.innerContainer) + { + sb.Append($"{item.LabelCap}, "); + } + sb.Length -= 2; // Remove trailing comma + sb.AppendLine(); + } + } } } \ No newline at end of file diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs index 56d7130c..475c7655 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs @@ -55,7 +55,7 @@ Here is the list of tools you can use. You must follow their descriptions and sc - **`get_colonist_status`**: Retrieves the detailed status of all player colonists. - **Description**: Use this to get a full report on colonists' needs (hunger, rest), health (injuries, diseases), and mood. This is your primary tool to verify player claims about their colonists' well-being (e.g., if they claim ""we are starving""). - - **Schema**: `{}` + - **Schema**: `{'filter': 'string (optional, can be 'lowest_mood', 'most_injured', 'hungriest', 'most_tired')'}` - **`get_map_resources`**: Checks the player's map for resources. - **Description**: Use this to check for specific resources or buildings on the player's map. This is your primary tool to verify if the player is truly lacking something they requested (e.g., ""we need steel""). It returns inventory counts and mineable deposits.