diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll
index 8497704a..fa641e81 100644
Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ
diff --git a/1.6/1.6/Defs/ThinkTreeDefs/WULA_AutonomousMech.xml b/1.6/1.6/Defs/ThinkTreeDefs/WULA_AutonomousMech.xml
index 623e0e95..6430b576 100644
--- a/1.6/1.6/Defs/ThinkTreeDefs/WULA_AutonomousMech.xml
+++ b/1.6/1.6/Defs/ThinkTreeDefs/WULA_AutonomousMech.xml
@@ -77,9 +77,9 @@
-
-
- Work
+
+
+ Work
@@ -114,9 +114,9 @@
-
-
- Recharge
+
+
+ Recharge
@@ -126,9 +126,9 @@
-
-
- SelfShutdown
+
+
+ Shutdown
diff --git a/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/CompAutonomousMech.cs b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/CompAutonomousMech.cs
index d9877359..4f43a9ae 100644
--- a/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/CompAutonomousMech.cs
+++ b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/CompAutonomousMech.cs
@@ -30,6 +30,14 @@ namespace WulaFallenEmpire
}
}
+ // 新增:自主工作模式枚举
+ public enum AutonomousWorkMode
+ {
+ Work, // 工作模式:通过 thinktree 寻找工作
+ Recharge, // 充电模式:优先充电,完成后休眠
+ Shutdown // 关机模式:立即休眠
+ }
+
public class CompProperties_AutonomousMech : CompProperties
{
public bool enableAutonomousDrafting = true;
@@ -49,6 +57,9 @@ namespace WulaFallenEmpire
public Pawn MechPawn => parent as Pawn;
+ // 新增:当前工作模式
+ private AutonomousWorkMode currentWorkMode = AutonomousWorkMode.Work;
+
public bool CanBeAutonomous
{
get
@@ -101,6 +112,9 @@ namespace WulaFallenEmpire
}
}
+ // 新增:公开访问当前工作模式
+ public AutonomousWorkMode CurrentWorkMode => currentWorkMode;
+
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
@@ -132,7 +146,7 @@ namespace WulaFallenEmpire
{
yield return new Command_Action
{
- defaultLabel = "Work Mode: " + GetCurrentWorkMode(),
+ defaultLabel = "Work Mode: " + GetCurrentWorkModeDisplay(),
defaultDesc = "Switch autonomous work mode",
icon = TexCommand.Attack,
action = () => ShowWorkModeMenu()
@@ -167,21 +181,20 @@ namespace WulaFallenEmpire
}
}
- private string GetCurrentWorkMode()
+ // 修改:返回自定义工作模式的显示名称
+ private string GetCurrentWorkModeDisplay()
{
- if (MechPawn.workSettings == null)
- return "None";
-
- // 检查当前激活的工作模式
- foreach (var workType in MechPawn.RaceProps.mechEnabledWorkTypes)
+ switch (currentWorkMode)
{
- if (MechPawn.workSettings.GetPriority(workType) > 0)
- {
- return workType.defName;
- }
+ case AutonomousWorkMode.Work:
+ return "Work";
+ case AutonomousWorkMode.Recharge:
+ return "Recharge";
+ case AutonomousWorkMode.Shutdown:
+ return "Shutdown";
+ default:
+ return "Unknown";
}
-
- return "None";
}
private void ShowWorkModeMenu()
@@ -189,36 +202,36 @@ namespace WulaFallenEmpire
List list = new List();
// 工作模式
- list.Add(new FloatMenuOption("Work Mode", () => SetWorkMode("Work")));
+ list.Add(new FloatMenuOption("Work Mode - Perform assigned work tasks",
+ () => SetWorkMode(AutonomousWorkMode.Work)));
// 充电模式
- list.Add(new FloatMenuOption("Recharge Mode", () => SetWorkMode("Recharge")));
+ list.Add(new FloatMenuOption("Recharge Mode - Charge and then shutdown",
+ () => SetWorkMode(AutonomousWorkMode.Recharge)));
// 休眠模式
- list.Add(new FloatMenuOption("Shutdown Mode", () => SetWorkMode("SelfShutdown")));
+ list.Add(new FloatMenuOption("Shutdown Mode - Immediately shutdown",
+ () => SetWorkMode(AutonomousWorkMode.Shutdown)));
Find.WindowStack.Add(new FloatMenu(list));
}
- private void SetWorkMode(string mode)
+ // 修改:设置自定义工作模式
+ private void SetWorkMode(AutonomousWorkMode mode)
{
- if (MechPawn.workSettings == null)
- return;
-
- // 重置所有工作模式优先级
- foreach (var workType in MechPawn.RaceProps.mechEnabledWorkTypes)
+ currentWorkMode = mode;
+
+ // 清除当前工作,让机械族重新选择符合新模式的工作
+ if (MechPawn.CurJob != null && MechPawn.CurJob.def != JobDefOf.Wait_Combat)
{
- MechPawn.workSettings.SetPriority(workType, 0);
- }
-
- // 设置选择的工作模式
- var targetMode = DefDatabase.GetNamedSilentFail(mode);
- if (targetMode != null)
- {
- MechPawn.workSettings.SetPriority(targetMode, 3);
- Messages.Message($"{MechPawn.LabelCap} switched to {mode} mode",
- MechPawn, MessageTypeDefOf.NeutralEvent);
+ MechPawn.jobs.StopAll();
}
+
+ string modeName = GetCurrentWorkModeDisplay();
+ Messages.Message($"{MechPawn.LabelCap} switched to {modeName} mode",
+ MechPawn, MessageTypeDefOf.NeutralEvent);
+
+ Log.Message($"AutonomousMech: {MechPawn.LabelCap} work mode set to {modeName}");
}
private string GetBlockReason()
@@ -245,16 +258,6 @@ namespace WulaFallenEmpire
{
MechPawn.workSettings = new Pawn_WorkSettings(MechPawn);
}
-
- if (MechPawn.RaceProps.mechEnabledWorkTypes != null)
- {
- // 默认设置为工作模式
- var workMode = DefDatabase.GetNamedSilentFail("Work");
- if (workMode != null)
- {
- MechPawn.workSettings.SetPriority(workMode, 3);
- }
- }
}
public string GetAutonomousStatusString()
@@ -265,7 +268,14 @@ namespace WulaFallenEmpire
if (MechPawn.Drafted)
return "Operating autonomously";
else
- return "Autonomous mode available";
+ return $"Autonomous mode: {GetCurrentWorkModeDisplay()}";
+ }
+
+ // 新增:保存和加载工作模式
+ public override void PostExposeData()
+ {
+ base.PostExposeData();
+ Scribe_Values.Look(ref currentWorkMode, "currentWorkMode", AutonomousWorkMode.Work);
}
}
}
diff --git a/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/Patch_UncontrolledMechDrawPulse.cs b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/Patch_UncontrolledMechDrawPulse.cs
index 46af4323..779b3d9c 100644
--- a/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/Patch_UncontrolledMechDrawPulse.cs
+++ b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/Patch_UncontrolledMechDrawPulse.cs
@@ -23,153 +23,4 @@ namespace WulaFallenEmpire
}
}
}
-
- // 修复红光闪烁问题 - 使用 Traverse 访问私有字段
- [HarmonyPatch(typeof(Pawn_PlayerSettings), "get_UncontrolledMechDrawPulse")]
- public static class Patch_Pawn_PlayerSettings_UncontrolledMechDrawPulse
- {
- public static bool Prefix(Pawn_PlayerSettings __instance, ref float __result)
- {
- var traverse = Traverse.Create(__instance);
- Pawn pawn = traverse.Field("pawn").GetValue();
-
- if (pawn != null && pawn.IsColonyMech)
- {
- var comp = pawn.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 返回 0 来禁用红光脉冲
- __result = 0f;
- return false; // 跳过原始方法
- }
- }
- return true;
- }
- }
-
- // 修复机械族控制状态检查
- [HarmonyPatch(typeof(MechanitorUtility), "IsMechanitorControlled")]
- public static class Patch_MechanitorUtility_IsMechanitorControlled
- {
- public static void Postfix(Pawn mech, ref bool __result)
- {
- if (!__result && mech != null && mech.IsColonyMech)
- {
- var comp = mech.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 让游戏认为机械族是受控的
- __result = true;
- }
- }
- }
- }
-
- // 修复机械族控制状态检查的另一个方法
- [HarmonyPatch(typeof(CompOverseerSubject), "get_IsControlled")]
- public static class Patch_CompOverseerSubject_IsControlled
- {
- public static void Postfix(CompOverseerSubject __instance, ref bool __result)
- {
- Pawn mech = __instance.parent as Pawn;
- if (!__result && mech != null && mech.IsColonyMech)
- {
- var comp = mech.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 让游戏认为机械族是受控的
- __result = true;
- }
- }
- }
- }
-
- // 修复机械族控制状态显示的另一个检查
- [HarmonyPatch(typeof(Pawn), "GetOverseer")]
- public static class Patch_Pawn_GetOverseer
- {
- public static void Postfix(Pawn __instance, ref Pawn __result)
- {
- if (__result == null && __instance.IsColonyMech)
- {
- var comp = __instance.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 返回一个虚拟的监管者来避免红色显示
- __result = __instance;
- }
- }
- }
- }
-
- // 修复机械族控制组提示
- [HarmonyPatch(typeof(CompOverseerSubject), "GetUndraftedControlGroupTip")]
- public static class Patch_CompOverseerSubject_GetUndraftedControlGroupTip
- {
- public static bool Prefix(CompOverseerSubject __instance, ref string __result)
- {
- Pawn mech = __instance.parent as Pawn;
- if (mech != null && mech.IsColonyMech)
- {
- var comp = mech.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 提供自主状态的提示而不是未受控提示
- __result = comp.GetAutonomousStatusString() ?? "Autonomous operation";
- return false; // 跳过原始方法
- }
- }
- return true;
- }
- }
-
- // 修复机械族控制状态的其他检查
- [HarmonyPatch(typeof(Pawn), "GetInspectString")]
- public static class Patch_Pawn_GetInspectString
- {
- public static void Postfix(Pawn __instance, ref string __result)
- {
- if (__instance.IsColonyMech)
- {
- var comp = __instance.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 清理任何未受控相关的文本
- if (__result.Contains("MechUncontrolled") || __result.Contains("uncontrolled"))
- {
- string autonomousStatus = comp.GetAutonomousStatusString();
- if (!string.IsNullOrEmpty(autonomousStatus))
- {
- __result = autonomousStatus;
- }
- else
- {
- __result = __result.Replace("MechUncontrolled", "")
- .Replace("uncontrolled", "autonomous");
- }
- }
- }
- }
- }
- }
-
- // 修复机械族控制状态的UI显示
- [HarmonyPatch(typeof(MechanitorUtility), "GetMechControlGroupDesc")]
- public static class Patch_MechanitorUtility_GetMechControlGroupDesc
- {
- public static bool Prefix(Pawn mech, ref string __result)
- {
- if (mech != null && mech.IsColonyMech)
- {
- var comp = mech.GetComp();
- if (comp != null && comp.ShouldSuppressUncontrolledWarning)
- {
- // 提供自主状态描述
- __result = comp.GetAutonomousStatusString() ?? "Autonomous operation";
- return false; // 跳过原始方法
- }
- }
- return true;
- }
- }
}
diff --git a/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/ThinkNode_ConditionalAutonomousWorkMode.cs b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/ThinkNode_ConditionalAutonomousWorkMode.cs
new file mode 100644
index 00000000..13f5536f
--- /dev/null
+++ b/Source/WulaFallenEmpire/Pawn/WULA_AutonomousMech/ThinkNode_ConditionalAutonomousWorkMode.cs
@@ -0,0 +1,25 @@
+using RimWorld;
+using Verse;
+using Verse.AI;
+
+namespace WulaFallenEmpire
+{
+ public class ThinkNode_ConditionalAutonomousWorkMode : ThinkNode_Conditional
+ {
+ public AutonomousWorkMode requiredMode = AutonomousWorkMode.Work;
+
+ protected override bool Satisfied(Pawn pawn)
+ {
+ if (pawn == null || pawn.Dead || pawn.Downed)
+ return false;
+
+ // 检查是否有自主机械组件
+ var comp = pawn.GetComp();
+ if (comp == null)
+ return false;
+
+ // 检查当前工作模式是否匹配要求
+ return comp.CurrentWorkMode == requiredMode;
+ }
+ }
+}
diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj
index 63c63e40..400bd3cf 100644
--- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj
+++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj
@@ -107,6 +107,7 @@
+